⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edit.cs

📁 编译器
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace PlxCompiler
{
    public partial class Edit : Form
    {
        Form1 form1;
        public bool changed;
        int ColIndex;
        int RowIndex;
        int RowStartIndex; 

        public Edit(PlxCompiler.Form1 parent,string name)
        {
            InitializeComponent();
            this.MdiParent = parent;
            this.Text = name;
            //richTextBox1.se
            form1 = parent;
            changed = false;
        }

        public void font(Font font1)
        {

            richTextBox1.Font  = font1;
            //richTextBox1.SelectAll();
           // richTextBox1.SelectionFont = richTextBox1.Font;
            //richTextBox1.Select();

        }
        public void Menu_Redo(Object sender, EventArgs e)
        {
            // Determines if a Redo operation can be performed.
            if (richTextBox1.CanRedo == true)
            {
                // Determines if the redo operation deletes text.
                if (richTextBox1.RedoActionName != "Delete")
                    // Perform the redo.
                    richTextBox1.Redo();
            }
        }
        public void Menu_Copy(System.Object sender, System.EventArgs e)
        {
            // Ensure that text is selected in the text box.   
            if (richTextBox1.SelectionLength > 0)
                // Copy the selected text to the Clipboard.
                richTextBox1.Copy();
        }

        public void Menu_Cut(System.Object sender, System.EventArgs e)
        {
            // Ensure that text is currently selected in the text box.   
            if (richTextBox1.SelectedText != "")
                // Cut the selected text in the control and paste it into the Clipboard.
                richTextBox1.Cut();
        }

        public void Menu_Paste(System.Object sender, System.EventArgs e)
        {
            // Determine if there is any text in the Clipboard to paste into the text box.
            if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true)
            {
                // Determine if any text is selected in the text box.
                if (richTextBox1.SelectionLength > 0)
                {
                    // Ask user if they want to paste over currently selected text.
                    //if (MessageBox.Show("Do you want to paste over current selection?", "Cut Example", MessageBoxButtons.YesNo) == DialogResult.No)
                        // Move selection to the point after the current selection and paste.
                        richTextBox1.SelectionStart = richTextBox1.SelectionStart + richTextBox1.SelectionLength;
                }
                // Paste current text in Clipboard into text box.
                richTextBox1.Paste();
            }
        }

        public void Menu_Select(Object sender, EventArgs e)
        {
            richTextBox1.SelectAll();
        }
        public void Menu_Undo(System.Object sender, System.EventArgs e)
        {
            // Determine if last operation can be undone in text box.   
            if (richTextBox1.CanUndo == true)
            {
                // Undo the last operation.
                richTextBox1.Undo();
                // Clear the undo buffer to prevent last action from being redone.
                richTextBox1.ClearUndo();
            }
        }
        //读取文件
        public void Load_File(string filename)
        {
            StreamReader sr = new StreamReader(filename, System.Text.Encoding.Default, true);
            richTextBox1.Text = sr.ReadToEnd();//File.ReadAllText(filename); 
            richTextBox1.SelectAll();
            richTextBox1.SelectionFont = richTextBox1.Font;
            richTextBox1.Select(0, 0);

        }

        private void richTextBox1_RegionChanged(object sender, EventArgs e)
        {
            MessageBox.Show("Input project name....", "Project", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            //form1.setColumRow(richTextBox1.Text.Length + "", "Row " + Cursor.Position.X, "Colum " + Cursor.Position.Y);
            changed = true;
            //int a = SplitterCancelEventArgs.MouseCursorY;
        }

        private void richTextBox1_MouseLeave(object sender, EventArgs e)
        {
           // form1.setColumRow(richTextBox1.Text.Length + "", "Row " + "Colum " + Cursor.Position.Y);
            
        }

        private void richTextBox1_MouseCaptureChanged(object sender, EventArgs e)
        {
            //form1.setColumRow(richTextBox1.Text.Length + "", "Row " + Cursor.Position.X, "Colum " + Cursor.Position.Y);
        }

        private void richTextBox1_MouseMove(object sender, MouseEventArgs e)
        {
            RowIndex = richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart) + 1;
            // Console.WriteLine ("Row: " + RowIndex.ToString()); 

            //richTextBox1.GetCharIndexFromPosition((richTextBox1.GetPositionFromCharIndex - (richTextBox1.SelectionStart)));
            RowStartIndex = Win32.SendMessage(richTextBox1.Handle, Win32.EM_LINEINDEX, -1, 0);
            ColIndex = richTextBox1.SelectionStart - RowStartIndex + 1;
            //Console.WriteLine("Col:" + ColIndex.ToString()); 
            form1.setColumRow("Total " + richTextBox1.Text.Length + "", "Row " + RowIndex, "Colum " + ColIndex);
      
        }

        private void Edit_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (changed)
            {
                if (MessageBox.Show(Text + " 已经改动是否保存....", "已修改", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                    Save_file();
            }
           
            form1.close_window(this.Text);
        }
        public bool Save_file()
        {

            try
            {
                //FileStream saveFile = new FileStream(this.Text, FileMode.OpenOrCreate);
                //StreamWriter fileWrite = new StreamWriter(saveFile,Encoding.UTF8);
                //fileWrite.Write(this.richTextBox1.Text.Normalize());
                //fileWrite.Close();
                this.richTextBox1.SaveFile(this.Text, RichTextBoxStreamType.PlainText); 
                form1.show("已保存文件 " +Text + "..\r\n");
                this.changed = false;
                return true;
            }
            catch (IOException e)
            {
               return false ;
                
            }

        }
        public bool Save_file(string name)
        {

            try
            {
                //FileStream saveFile = new FileStream(name, FileMode.OpenOrCreate);
                //StreamWriter fileWrite = new StreamWriter(saveFile,Encoding.UTF8);
                //fileWrite.Write(this.richTextBox1.Text);
                //fileWrite.Close();
                this.richTextBox1.SaveFile(name, RichTextBoxStreamType.PlainText); 
                form1.show("已保存文件 " + name + "...\r\n");
                this.changed = false;
                return true;
            }
            catch (IOException e)
            {
                return false;
            }

        }

        private void richTextBox1_Move(object sender, EventArgs e)
        {

        }

        private void richTextBox1_KeyUp(object sender, KeyEventArgs e)
        {
            RowIndex = richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart) + 1;
            // Console.WriteLine ("Row: " + RowIndex.ToString()); 

            //richTextBox1.GetCharIndexFromPosition((richTextBox1.GetPositionFromCharIndex - (richTextBox1.SelectionStart)));
            RowStartIndex = Win32.SendMessage(richTextBox1.Handle, Win32.EM_LINEINDEX, -1, 0);
            ColIndex = richTextBox1.SelectionStart - RowStartIndex + 1;
            //Console.WriteLine("Col:" + ColIndex.ToString()); 
            form1.setColumRow("Total "+richTextBox1.Text.Length + "", "Row " + RowIndex, "Colum " + ColIndex);
            //richTextBox1.GetLineFromCharIndex(richTextBox1.sle
        }

      
    }
    public class Win32
    {
        public Win32()
        {
            // 
            // TODO: Add constructor logic here 
            // 
        }
        [System.Runtime.InteropServices.DllImport("User32.Dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        public const int EM_LINEINDEX = 0xBB;
    } 


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -