Tag: winforms

StartPosition设置为CenterPosition,但我的表单不居中

我正在使用Visual Studio 2012.我的表单在打开时不会以屏幕为中心。 我将表单的StartPosition设置为CenterScreen ,但它总是从我左侧监视器的左上角开始(我有2个监视器)。 有任何想法吗? 谢谢

C# – 跨表单使用ColorDialog

我有一个Windows窗体应用程序。 在主窗体上,用户将输入一些项目等,然后单击一个按钮,该按钮将打开一个新窗体(小窗体或大窗体,具体取决于复选框)。 现在,在我的主应用程序中,我有一个文件菜单 – 在其下设置 – 更改背景颜色。 这打开了colordialog。 如果用户没有选择任何内容,则背景颜色将保持默认。 但是,如果他们在主条目表单上更改它,我会更改几个文本框的背景 – 下面的代码。 private void warning1ToolStripMenuItem_Click(object sender, EventArgs e) { colorDialog1.ShowDialog(); Warn1Color = colorDialog1.Color.ToString(); if (Warn1Color != null) { tbWarn1Hrs.BackColor = colorDialog1.Color; tbWarn1Mins.BackColor = colorDialog1.Color; tbWarn1Secs.BackColor = colorDialog1.Color; tbWarn1Msg.BackColor = colorDialog1.Color; } } 现在我的问题是我如何得到它然后更改打开的其他窗体中的背景。 我希望我可以在新表单构造函数中传递字符串,就像我使用其他一些值一样。 ie – 这是我在新表单中的代码….(注意 – 字符串Warn1Color在构造函数中传递,然后使= =字符串_Warn1Color。如果它为null,则背景将默认为黄色,但它无法将类型字符串转换为system.drawing.color。有没有人看到一个简单的解决方案,或者我可以做些什么来轻松地工作。 if (_Warn1Color == null) { […]

WinForms.Charting抑制自动生成图例

我正在使用System.Windows.Forms.DataVisualization.Charting.Chart类绘制包含一些数据的图表。 现在我想禁止在图例中自动生成条目,并用自定义项替换它们。 我已经找到了添加自定义项目的方法,但无法抑制自动生成。 我的代码: var legend = new Legend(); legend.LegendStyle = LegendStyle.Table; legend.TableStyle = LegendTableStyle.Wide; legend.IsEquallySpacedItems = true; legend.IsTextAutoFit = true; legend.BackColor = Color.White; legend.Font = new Font(Config.FontFamily, 9); legend.Docking = Docking.Bottom; legend.Alignment = StringAlignment.Center; legend.CustomItems.Add(new LegendItem(“test”, Color.Green, string.Empty)); ch.Legends.Add(legend); 以前有人做过这样的事吗?

绘制位图C#

我试图在屏幕上用位图类绘制图像,但有些错误。 这是我的代码: Bitmap bm = new Bitmap(@”C:\Alan\University\111.jpg”); Graphics g = Graphics.FromImage(bm); g.DrawImage(bm,60,60); 运行代码后,我的屏幕上没有任何附加信息。 我的代码有什么问题? 谢谢

表格/窗口后面出现的工具提示! (C#/ VS 2008)

出于一些奇怪的原因,我在VS 2008 C#winforms应用程序中的toopltip显示在表单后面! 这非常令人沮丧,我无法弄清楚我应该做些什么。 以前有人面对这个吗? 想法? (PS – 我在表单中以编程方式执行toolstip.show)

如何创建包含IPv4地址的文本框?

如何制作这样的文本框? 我认为以前所有的使用都已经看过,并且知道它的function。

使用IP地址打印到网络打印机

我想发送文件名和打印机的IP地址来指定要打印的打印机。 我收到一条错误消息“访问打印机的设置’xxx.xxx.xxx.xxx’无效。” 当我到printdoc.Print()。 如何根据IP地址设置要打印的打印机? printdoc = new PrintDocument(); printdoc.PrinterSettings.PrinterName = IPAddress.Trim; printdoc.DocumentName = FileName; printdoc.Print(); 如何解决这个问题?它的ac#vs2010独立Windows应用程序

强制轨迹栏值为十倍

我在使用C#的Winform项目中添加了一个轨迹栏。 mySlider.Minimum = 0; mySlider.Maximum = 200; mySlider.Value = 30; mySlider.SmallChange = 10; mySlider.LargeChange = 10; mySlider.TickFrequency = 10; 我希望能够只选择十个倍数值。 我没有找到解决方案来做到这一点。 请问最好的方法是什么?

只调用一个Paint事件

我的问题是我有8个图片盒,其中只有一个是一次调用他们的绘图方法。 我的代码有点太大,所以我尽量把它缩小到受影响的部分。 我最好的猜测是,它不是我的代码中的错误,而是对绘制事件如何工作的误解。 我有一个inheritance自PictureBox的类,而不是Picturebox。 唯一的变化是构造函数 using System.Drawing; using System.Windows.Forms; public class DrawingSurface : PictureBox { public DrawingSurface(Rectangle bounds) : base() { base.Dock = DockStyle.Fill; base.SizeMode = PictureBoxSizeMode.Zoom; //I set the size and bounds which is probably redundant because //I was trying random things to fix the problem base.Size = new Size(bounds.Width, bounds.Height); base.Bounds = bounds; […]

C#如何使用选取框进度条加载表单?

我创建了一个只有带字幕样式的进度条的loadingForm。 在我的mainForm中我试图这样做: //before downloading loadingForm lf = new loadingForm(); lf.Show(); //start downloading //finishdownloading lf.Close(); 显示了loadingForm但没有出现进度条,表格看起来像是崩溃了。 完成下载后,loadingForm关闭,我的应用程序继续正常运行。 在loadingForm我只有: void loadingForm_Load(object sender, EventArgs e) { progressbar1.visible = true; } 我已经将progressbar1样式设置为loadingForm.design中的选取框。 我该如何解决? 感谢您的帮助。