Tag: winforms

如何画线并在Panel中选择它

我的程序可以使用canvas.Drawline()绘制线条。 如何点击线并更改此颜色(选择线)? private List coordFirst = new List(); private List coordLast = new List(); public Graphics canvas; private void Form1_Load(object sender, EventArgs e) { canvas=panel1.CreateGraphics(); } 存储在coordFirs和coodLast中的坐标线。

根据当前鼠标位置缩放图形

我正在尝试根据鼠标的当前位置缩放绘图。 现在我的onMouseWheel方法看起来像这样(基于这个StackOverflow答案 ): private void onMouseWheel(object sender, MouseEventArgs e) { if (e.Delta > 0) { _scale *= 1.25f; _translateY = eY – 1.25f * (eY – _translateY); _translateX = eX – 1.25f * (eX – _translateX); } else { _scale /= 1.25f; _translateY = eY – 0.8f * (eY – _translateY); _translateX = eX – […]

如何比较两个富文本框内容并突出显示更改的字符?

我用来读取2个richtextbox内容的代码如下: richTextBox1.Text = File.ReadAllText(tfsVersionFilePath); richTextBox2.Text = File.ReadAllText(dbVersionFilePath); 现在,我需要比较两个富文本框内容,并突出显示两个richtextbox中更改的字符。 目的是通过c#应用程序获取差异并突出显示as in TFS (比较文件)中的字符。 谢谢。 编辑: int length = (richTextBox1.Text.Length > richTextBox2.Text.Length) ? richTextBox1.Text.Length : richTextBox2.Text.Length; for (int i = 0; i < length; i++) { if (richTextBox1.Text[i] != richTextBox2.Text[i]) { /* and then start your highlight selection here, this is where some difference between the two […]

使用文件系统目录结构填充TreeView

我是新的节点在这里.. :)我想出了这个算法,但它只显示父节点列表..像这样.. a a.txt b c c m n b o p etc… 我希望下一个节点将被放入上一个节点内的一个节点..所以它会像这样出现.. a a.txt b o p c m n etc… 我有一些想法,但我可以实现它代码.. :)任何帮助请.. private void ListDirectory(TreeView treeView, String path) { Stack stack = new Stack(); TreeNode DirFilesCollection = new TreeNode(); stack.Push(path); while (stack.Count > 0) { string dir = stack.Pop(); try { List […]

Interop进程后无法关闭Excel.exe

我遇到了Excel Interop的问题。 即使我重新发布实例,Excel.exe也不会关闭。 这是我的代码: using xl = Microsoft.Office.Interop.Excel; xl.Application excel = new xl.Application(); excel.Visible = true; excel.ScreenUpdating = false; if (wordFile.Contains(“.csv”) || wordFile.Contains(“.xls”)) { //typeExcel become a string of the document name string typeExcel = wordFile.ToString(); xl.Workbook workbook = excel.Workbooks.Open(typeExcel, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing); object […]

将值从一个表单传递给另一个表单

我有两种forms,我需要从form1.textbox1传递一个值到form2.variable Form1中: string Ed = “”, En = “”; public string En1 { get { return En; } set { En = value; } } public string Ed1 { get { return Ed; } set { Ed = value; } } private void button1_Click(object sender, EventArgs e) { Form2 F2 = new Form2(); F2.Show(); F2.textbox1value […]

C#Windows窗体应用程序 – 从另一个线程AND类更新GUI?

我搜索了很多,但我似乎无法找到与我的具体问题有关的任何内容。 我希望能够从另一个类(SocketListener)更新我的MainUI表单,并且我有一个处理网络的线程(clientThread)。 现在我可以从网络线程运行简单的输出,例如写入调试器输出和创建MessageBox。 但我真正想做的是能够调用clientThread中的代码,该代码将在我的MainUI实例上执行操作。 我怎样才能做到这一点? 此外,如果有人想要代码的特定部分,那么我可以发布它,以帮助您更好地理解我的要求。 最好的祝福!

如何更改ListBox选择背景颜色?

它似乎使用Windows设置中的默认颜色,默认为蓝色。 假设我想永久地将它改为红色。 我正在使用Winforms。 提前致谢。

如何在winforms中制作多语言应用程序

我有一个应用程序,我需要在该应用程序中使用两种语言(例如,英语和阿拉伯语),但我不知道我该怎么做。 有人可以帮我这个吗? 我需要在C#Windows窗体中使用一些示例。

表单之间的交互 ​​- 如何从另一个表单更改表单的控件?

当我在第一个表单上的dataGridView中选择行以在另一个表单上用该值填充comboBox时,我想设置comboBox.SelectedValue, 在我的加载事件中的第二个表单上,我有comboBox.DataSource , DisplayMember , ValueMember正确设置但是当我首先设置selectedValue时没有发生任何事情。 当我在一个表格上做的时候,一切都很好