zoukankan      html  css  js  c++  java
  • 自写的 c# 锚点,书签,行高 读书笔记本 (二)

       话说,晚上又到了。。基地的门又快关了。。

    继续没记完的。

    //========

    3. 麻烦点的锚点(书签)

    4.前端显示功能和设置 行高

    //========

     书签我用的是自定义的一个数据结构方便以后扩展。

    Tree
    using System.Collections.Generic;
    namespace NoteBook
    {
    /// <summary>
    /// Tree 泛型
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class Tree<T>
    {
    /// <summary>
    /// 标题
    /// </summary>
    public string Text;
    /// <summary>
    /// 子类
    /// </summary>
    public IList<Tree<T>> ChildTree;
    /// <summary>
    /// 内容
    /// </summary>
    public T Content;
    public Tree()
    {
    ChildTree
    = new List<Tree<T>>();
    }
    public void AddChildTree(Tree<T> tree)
    {
    this.ChildTree.Add(tree);
    }
    }
    }

    不过确实比较丑。。。叠加的有点多。。。好在能解决问题。如果你也想自己造轮子的话。

    可以试试 用  一个简单是 ILIST<>就可以了。

    一个书签拥有的属性:     坐标 (X,Y)   +   注释   + 父子关系     《==》

    TREE<T>                  T(INT [])      +  Text+  ChildTree

    有了这么一个模型。 不管好或坏。我们可以简单的得到 操作。如下图

    代码
    #region ============获取查找=======================
    TreeNode CurrenttreeNode
    = e.Node;

    Tree
    <int[]> atree = new Tree<int[]>();

    atree.Text
    = CurrenttreeNode.Text;

    if (tree.ChildTree == null) { MessageBox.Show("没有数据"); return; }

    int i = 0;
    for (i = 0; i < tree.ChildTree.Count; i++)
    {
    if (atree.Text == tree.ChildTree[i].Text)
    { atree
    = tree.ChildTree[i]; break; }
    }



    #endregion

    接下来是找到了 坐标X,Y了。怎么在页面使得 数据高亮呢?

    转换XY并高亮之
    int k = tB_NoteContent.GetFirstCharIndexFromLine(atree.Content[1]);
    tB_NoteContent.SelectionStart
    = k + atree.Content[0];

    tB_NoteContent.Select(tB_NoteContent.SelectionStart,
    5);//找到
    tB_NoteContent.ScrollToCaret();//移动到

    tB_NoteContent.SelectionFont
    = SelectFont;
    tB_NoteContent.SelectionColor
    = SelectColor;

    有几个是 顾名思义的 函数。

    第一行 根据 Y行数 得到Y行第一个 字符在 全文中的 顺序。

    然后我们把 K+X 得到当初 标志的 位置,然后使用  RichTextBox 的选中 几个 字。 这里需要注意

    续选中的几个字可能会超出该行。咋办呢你可以 对 richtextbox . lines[y]  取出  该行的所有字符。 进行操作。

    这里蛮好玩的。自己试试。我这 时间 不多了,就不多说了。以后有时间再弄了。

    然后是设置属性,这个大家都知道了。

    到这里 书签的 查找就 OK了。至于书签的 添加:

    代码
    private void insetMaoToolStripMenuItem_Click(object sender, EventArgs e)
    {
    //先加载进内存树 然后加载进页面 保存的时候 保存进 一个专用的文档。 .KF
    //分别向 内存树 和 窗口 添加
    //1
    Tree<int[]> trees = new Tree<int[]>();
    trees.Text
    = tB_Node.Text.Trim();
    trees.Content
    = new int[] { x, y };
    //得到窗口树上的节点
    //找到对应的内存数的 节点并添加进去
    tree.AddChildTree(trees);
    //2
    treeNode = new TreeNode(trees.Text);

    MenuTree.Nodes.Add(treeNode);

    }

    这里我是注册进 鼠标右键 事件里的。再然后就是老套的存到本地。

    ===========================到此书签功能也就完了===================

     接下来是 永远的 前端显示 和 设置行高。

    前一个是我做这个程序的 初衷之一。XP自带的没前端显示就是不爽。

    第二个没有的话,看起来 忒郁闷。

    但是这是高手的活。。我暂时是 COPY来的 请参考

    前端显示

    http://www.yelaiju.com/article/149.aspx

    设置行高

    http://blog.csdn.net/firebird2010/archive/2009/11/30/4907923.aspx

    ==========================================================

    我今天最后做的一个功能是 目录扫描 上去。明天得复习还有作业,郁闷

    没时间弄代码了。

    也贴出来

    目录
    using System;
    using System.Collections;
    using System.IO;

    namespace Common
    {

    public class MyDirectory
    {
    protected readonly string DI = Environment.CurrentDirectory;

    private ArrayList fileList = new ArrayList();

    public ArrayList GetDirectory(string path) //遍历下一层次的目录
    {
    FileInfo[] fileInfos
    = GetFiles(path);


    foreach (FileInfo info in fileInfos)
    {
    fileList.Add(info);
    }


    return fileList;
    }

    public FileInfo GetAFile(string filename, string path)
    {
    FileInfo afileInfo
    = null;
    FileInfo[] fileInfos
    = GetFiles(path);
    foreach (FileInfo info in fileInfos)
    {
    if (info.ToString() == filename)
    {
    return info;
    }
    }
    return afileInfo;

    }


    public FileInfo[] GetFiles(string path)
    {
    DirectoryInfo directoryInfo
    = new DirectoryInfo(path);

    // DirectoryInfo[] directoryInfos = directoryInfo.GetDirectories();
    FileInfo[] fileInfos = directoryInfo.GetFiles();
    return fileInfos;
    }

    public static void reName(string oldepath, string newpath)
    {
    DirectoryInfo directoryInfo
    = new DirectoryInfo(oldepath);
    directoryInfo.MoveTo(newpath);
    }
    }
    }

    其他的都在源代码里。

    基地又关门了!。。闷啊。 

     下载地址

     https://files.cnblogs.com/facingwaller/NoteBook.rar


    作者:撞破南墙
    出处:http://www.cnblogs.com/facingwaller/
    关于作者:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    02-model设计
    01-开发环境搭建
    04-Uwsgi配置启动Nginx虚拟主机配置
    03-MySQL安装与配置
    02-Nginx配置
    01-Nginx安装
    22-注册、登录、验证登录
    21-django-pure-pagination分页
    (二)windows上使用docker
    Docker在windows7上的安装
  • 原文地址:https://www.cnblogs.com/facingwaller/p/1633660.html
Copyright © 2011-2022 走看看