winform

how to access winform components from another class?

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i have a form with one button and two labels and i have a separate class called myCounter i want the myCounter class to be able to access the labels in the form through a method called changeColor.. how can make the labels available in this class the form public partial class Form1 : Form { public Form1() { InitializeComponent(); } public Color colTurn { get { return lblp1Turn.BackColor; } set { lblp1Turn.BackColor = value; } } private void Form1_Load(object sender, EventArgs e) { } } the class class myCounter { private readonly Form1 Board;

Change Default Winform Icon Across Entire App

匿名 (未验证) 提交于 2019-12-03 02:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Can I change the default icon used on a Winform? Most of my forms have their icon property set to a custom icon. For the few forms that slip through the cracks, I don't want the generic "hey look, he made this in visual studio" icon. One solution is to tediously check every one of my forms to make sure they either have a custom icon set or have ShowIcon set to False. Another solution is to have every one of my forms inherit from a base class that sets a custom icon in the constructor. Aside from those solutions, what other options do I have?

C# WinForm - loading screen

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I would like to ask how to make a loading screen (just a picture or something) that appears while the program is being loaded, and disappears when the program has finished loading. in fancier versions, I have seen the process bar (%) displayed. how can you have that, and how do you calculate the % to show on it? I know there is a Form_Load() event, but I do not see a Form_Loaded() event, or the % as a property / attribute anywhere. 回答1: all you need to create one form as splash screen and show it before you main start showing the

Displaying a pdf file from Winform

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm just creating a simple calculator in C# (windows form) I've created a "User Help" which is a pdf file, what I want is to display that pdf file if the user clicks on the "Help" button in the WinForm. If assumed that Adobe reader is pre-installed on the user's machine.... How to open the pdf file on button click in winForm? I don't plan to provide this pdf file on hard disk of user. Which means that I have to embed this pdf into the calculator (winForm) and have to display it on the button click. Kindly guide me with the best

WinForm event subscription to another class

匿名 (未验证) 提交于 2019-12-03 01:36:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: public partial class Form1 : Form { private EventThrower _Thrower; public Form1() { InitializeComponent(); } private void DoSomething() { MessageBox.Show("It worked"); } private void button1_Click(object sender, EventArgs e) { _Thrower = new EventThrower(); //using lambda expression..need to use .NET2 so can't use this. _Thrower.ThrowEvent += (sender2, args) => { DoSomething(); }; var eventThrower = new EventThrower(); eventThrower.test(); } } public class EventThrower { public delegate void EventHandler(object sender, EventArgs args);

WinForm Control with Opacity

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a form that has some controls on itself(btnCreateReport,pnlDarkLayer).I have a panel that fit to form(Dock = Fill) and it is on the back of all controls.when user click on the btnCreateReport button ,I call pnlDarkLayer BringToFront method and after some calculation I call SendToBack() method of the button.I want to draw a dark layer on form controls and disable all of controls on the form. Is it possible? Thanks. Maybe this code help u to understand my purpose: private void btnCreateReport_Click(object sender, EventArgs e) {

winform窗体自适应大小

≡放荡痞女 提交于 2019-12-03 01:31:51
1.添加一个类class AutoSizeFormClass { //(1).声明结构,只记录窗体和其控件的初始位置和大小。 public struct controlRect { public int Left; public int Top; public int Width; public int Height; } //(2).声明 1个对象 //注意这里不能使用控件列表记录 List nCtrl;,因为控件的关联性,记录的始终是当前的大小。 // public List oldCtrl= new List();//这里将西文的大于小于号都过滤掉了,只能改为中文的,使用中要改回西文 public List<controlRect> oldCtrl = new List<controlRect>(); int ctrlNo = 0;//1; //(3). 创建两个函数 //(3.1)记录窗体和其控件的初始位置和大小, public void controllInitializeSize(Control mForm) { controlRect cR; cR.Left = mForm.Left; cR.Top = mForm.Top; cR.Width = mForm.Width; cR.Height = mForm.Height; oldCtrl.Add(cR);//第一个为

Winform 全局异常捕获

匿名 (未验证) 提交于 2019-12-03 00:43:02
初学 Winform 时,相信很多人都遇到过自己的程序在运行中出现了没有捕获的异常,导致程序退出的问题,在这种情况下,程序往往会弹出一个很不友好的信息框,然后强行退出。 程序出现了未捕获的异常,系统便认为它无法再继续工作了,所以强行结束了程序,这也是很正常的行为。但如果我们想要给用户显示一个比较友好的信息框,或者记录上传错误日志等等,那么就需要添加全局异常处理程序。 要为 Winform 程序添加全局异常处理程序,需要对 UI 线程和其他线程分别处理,代码如下: static class Program { /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { Application.EnableVisualStyles(); // 设置 UI 线程异常处理程序,必须在 Application.Run() 方法之前添加 Application.ThreadException += OnThreadException; // 要捕获其他线程的异常,必须先调用 SetUnhandledExceptionMode() 方法指示程序如何处理异常 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); // 设置其他线程异常处理程序

C#-Winform知识点

匿名 (未验证) 提交于 2019-12-03 00:33:02
Winform知识点1 1. 窗体组成 1. using System; //系统生成的命名空间 2. using System.Collections.Generic; 3. using System.ComponentModel; 4. using System.Data; 5. using System.Drawing; 6. using System.Text; 7. using System.Windows.Forms; 8. namespace Title //命名空间 9. { 10. public partial class Form1 : Form //Form 类在 System.Windows.Forms 命名空间中 11. { 12. public Form1() //构造方法 13. { 14. InitializeComponent(); //初始化方法 15. } 16. } 17. } 从第1行到第7行是系统自动生成的命名空间,在本例中用到 using System.Windows.Forms。第10行定义的Form1 类是本程序的窗体类,从Form 类继承。类名由窗体的Name属性决定,如果不指定则默认为Form1。 构造方法中惟一的方法―― InitializeComponent()方法。从名字上可以看出,这个方法起到初始化作用。右击

Visual Studio 中两个窗体(WinForm)之间相互传值的方法

匿名 (未验证) 提交于 2019-12-03 00:32:02
编写WinowsForm应用程序时,实现两个窗体之间相互传递值的方法其实很简单。以下用一个例子说明:在名为FormMain主窗体运行过程中利用名为FormInfo窗体,获取用户输入信息,并将这些信息返回给FormMain 1. FormMain和FormInfo 点击“修改...”按钮,显示FormInfo 2. 设置FormInfo中buttonOK和buttonCancal的属性 3. FormMain代码 public partial class FormMain : Form { public FormMain() { InitializeComponent(); } private void buttonInfo_Click( object sender, EventArgs e) { // 实例化FormInfo,并传入待修改初值 var formInfo = new FormInfo(labelInfo.Text); // 以对话框方式显示FormInfo if (formInfo.ShowDialog() == DialogResult.OK) { // 如果点击了FromInfo的“确定”按钮,获取修改后的信息并显示 labelInfo.Text = formInfo.Information; } } } 4. FormInfo代码 public partial