C# textbox 拖动控件 App(2) 向文本写入数据,或生成文本
C# textbox 拖动控件 App(2) 向文本写入数据,或生成文本
1.控件的事件可右击控件->控件属性,进行设置
2. 文件工具类(FileUtil.cs)
同一个命名空间可直接调用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
//file using System.IO; namespace FileDemo { class UdFileUtil { public static void readFile(string filePath) {//写入 FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); for (int i = 0; i < 10; i++) { sw.WriteLine( "tablenname" + " = {"); sw.WriteLine( "attr1 = " + "attr_value" + ","); sw.WriteLine("}"); } sw.Close(); fs.Close(); } } }
Form1.cs 调用
private void textBox1_DragEnter(object sender, DragEventArgs e) { Console.WriteLine(" textBox1_DragEnter"); //this.textBox1.Cursor = System.Windows.Forms.Cursors.Arrow;//指定鼠标形状 not use //this.textBox1.Cursor = System.Windows.Forms.Cursors.IBeam; not use string fullPath = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); if (File.Exists(fullPath)) //如果是文件的话,则截取 { //string path = fullPath.Substring(0, fullPath.LastIndexOf("\\")); textBox1.Text = fullPath; // fullPath文件路径 string str = fullPath; UdFileUtil.readFile(fullPath); } else { textBox1.Text = fullPath; } }
------ THE END !!
 
                    
                     
                    
                 
                    
                 
 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号