winform

winform程序窗体相关设置

血红的双手。 提交于 2020-01-28 12:00:37
在winform程序设计中经常会遇到一些设置性问题,在此记录总结一些经常遇到的小问题。 1.MDI多窗体程序中,子窗口点击最大化,会出现看到子窗口的icon显示在菜单中,而实际上正常状态下子窗口的showIcon属性是false的。但最大化之后就是出显示在父窗口的菜单栏上,默认icon看起来不太好看。 这情况怎么样出掉icon.就是子窗口最大化不是显示icon。 做法: 在父窗体的MenuStrip控件中添加一个ItemAdd事件 menuStrip_ItemAdded事件中添加如下代码: View Code /// <summary> /// 子窗口最大化时去掉主窗体菜单的icon图标 /// 在mdi子窗体最大化的时候,会发生如下动作: /// 会在父窗体的MenuStrip上添加4个Item. /// 分别为Icon,最大化,恢复跟最小化。 /// 其中除了Icon之外,其他三个的Text属性都赋予了文本值。 /// 另外,Icon作为MenuStrip的第一项Item,它的索引为0. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuStrip1_ItemAdded( object sender,

winform获取文件路径

ぐ巨炮叔叔 提交于 2020-01-28 03:39:55
1、取得控制台应用程序的根目录方法 方法1、Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径 方法2、AppDomain.CurrentDomain.BaseDirectory 获取基目录,它由程序集冲突解决程序用来探测程序集 2、取得Web应用程序的根目录方法 方法1、HttpRuntime.AppDomainAppPath.ToString();//获取承载在当前应用程序域中的应用程序的应用程序目录的物理驱动器路径。用于App_Data中获取 方法2、Server.MapPath("") 或者 Server.MapPath("~/");//返回与Web服务器上的指定的虚拟路径相对的物理文件路径 方法3、Request.ApplicationPath;//获取服务器上ASP.NET应用程序的虚拟应用程序根目录 3、取得WinForm应用程序的根目录方法 1、Environment.CurrentDirectory.ToString();//获取或设置当前工作目录的完全限定路径 2、Application.StartupPath.ToString();//获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称 3、Directory.GetCurrentDirectory();//获取应用程序的当前工作目录 4、AppDomain

winform窗体全屏

蓝咒 提交于 2020-01-27 05:42:45
bool fullscreen = false; Rectangle rect = new Rectangle(); private void button4_Click(object sender, EventArgs e) { fullscreen = !fullscreen;//循环。点一次全屏,再点还原。 SetFullScreen(fullscreen, ref rect); if (fullscreen) { this.WindowState = FormWindowState.Maximized;//全屏 } else { this.WindowState = FormWindowState.Normal;//还原 } } /// <summary> /// 设置全屏或这取消全屏 /// </summary> /// <param name="fullscreen">true:全屏 false:恢复</param> /// <param name="rectOld">设置的时候,此参数返回原始尺寸,恢复时用此参数设置恢复</param> /// <returns>设置结果</returns> public static bool SetFullScreen(bool fullscreen, ref Rectangle rectOld) { int Hwnd = 0;

winform 窗体、多线程影响

柔情痞子 提交于 2020-01-27 00:05:57
1.窗体的隐藏与显示 this.show() this.Hide() 2.MDI多文档界面 设置父窗体,IsMDIContainer = true; 设置子窗体,Form2 fr2 = new Form2(); fr2.MdiParent = this; fr2.Show(); MDI子窗体排列:MDILayOut.Horizal:水平平铺,垂坠平铺,叠层平铺 3.继承窗体实现的两种方式: 通过编写代码 :Form2 : WinFormApplication.Form1;一定是命名空间.窗体对象; 通过窗体选择器:通过项目添加winform窗体中的继承窗体。 修改子窗体中控件的属性,父窗体中的属性Medifiers设置为public,否则不能修改子窗体中的属性。 4.读取注册表中的信息 主要通过RegistryKey类中的OpenSubKey方法,GetSubKeyNames方法,GetValueNames方法实现 5.使用多线程的3种情况 1)执行占用大量时间的操作 2)区分具有不同优先级的任务 3)使用户界面可以在将时间分配给后台任务时仍能快速做出响应 6.使用多线程将产生的不良情况 1)因为线程为占用内存空间,使用多线程后,创建进程、AppDomain对象及线程数目将受到内存的限制 2)跟踪大量的线程将耗费大量的处理器时间,如果线程过多,则其中大多数线程不会产生明显的进度

Winform中DataGridView绑定IList数据源后的排序

强颜欢笑 提交于 2020-01-26 23:09:01
首先,实现ICompare接口 ObjectPropertyCompare public class ObjectPropertyCompare < T > : IComparer < T > { private PropertyDescriptor property; private ListSortDirection direction; // 构造函数 public ObjectPropertyCompare(PropertyDescriptor property, ListSortDirection direction) { this .property = property; this .direction = direction; } // 实现IComparer中方法 public int Compare(T x, T y) { object xValue = x.GetType().GetProperty(property.Name).GetValue(x, null ); object yValue = y.GetType().GetProperty(property.Name).GetValue(y, null ); int returnValue; if (xValue is IComparable) { returnValue = ((IComparable

WinForm 登录窗体 + 单实例运行

旧城冷巷雨未停 提交于 2020-01-26 02:51:15
关于怎么在winform里增加登录窗体或者如何让winform程序单实例运行网上都很多例子。 然而两者结合起来呢? //Program.cs static class Program { public static EventWaitHandle ProgramStarted; /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { bool createNew; ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, "MSFTD_SERVICE", out createNew); if (!createNew) { ProgramStarted.Set(); return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain

Winform中DataGridView绑定IList数据源后的排序

牧云@^-^@ 提交于 2020-01-26 01:43:06
首先,实现ICompare接口 public class ObjectPropertyCompare<T> : IComparer<T> { private PropertyDescriptor property; private ListSortDirection direction; // 构造函数 public ObjectPropertyCompare(PropertyDescriptor property, ListSortDirection direction) { this.property = property; this.direction = direction; } // 实现IComparer中方法 public int Compare(T x, T y) { object xValue = x.GetType().GetProperty(property.Name).GetValue(x, null); object yValue = y.GetType().GetProperty(property.Name).GetValue(y, null); int returnValue; if (xValue is IComparable) { returnValue = ((IComparable)xValue).CompareTo(yValue); }

Winform中调用WPF控件

依然范特西╮ 提交于 2020-01-24 23:48:01
有两种调用方式,在使用之前都将控件“ElementHost”添加到 Form 中: 方式一: 直接声明wpf中控件(使用 Windows.Controls) Public Class Form1 Dim txt As Windows.Controls.TextBox = New Windows.Controls.TextBox() Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load txt.SpellCheck.IsEnabled = True ElementHost1.Child = txt End Sub End Class 方式二: 首先新建一个 ”User Control“, 之后,如下编辑“UserControl1.xaml”中的内容: <Grid> <TextBox x:Name="textBox" Foreground="Black" FontSize="24" Margin="0"></TextBox> <TextBox SpellCheck.IsEnabled="True" /> </Grid> 最后,修改”Form1.vb“代码如下: Public Class Form1 Private uc As UserControl1 = New UserControl1

WinForm中调用WPF控件

a 夏天 提交于 2020-01-24 23:46:11
WinForm中调用WPF控件 在WinForm中可以使用WPF中的控件,或者由WPF创建的自定义控件; 步骤1:创建WinForm工程; 步骤2:在WinForm工程的解决方案资源管理器中,在刚刚创建的WinForm解决方案中新建或者添加现有的WPF用户控件工程; 步骤3:在WPF中创建自定义的控件,或者添加WPF控件到面板上; 步骤4:在WinForm面板上添加ElementHost控件(工具箱中); 步骤5:生成解决方案; 步骤6:在刚刚的ElementHost中的Child属性中添加刚刚的WPF生成的控件; 步骤7:完成。 如果在ElementHost的Child属性中添加了WPF生成的控件,编译的时候出现如下错误: 错误 1 类型“System.Windows.Markup.IComponentConnector”在未被引用的程序集中定义。必须添加对程序集“System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”的引用。 则要在WinForm中解决方案-> 添加引用->System.Xaml,类似的错误,就添加相应的引用。 如何在winform中调用WPF用户控件里面的属性和方法呢 ,如图: WinForm工程为test

[原][C#]winform使用html做界面

偶尔善良 提交于 2020-01-24 15:03:08
DirectUI技术开发界面的好奇 今天想到 怎么不让winform也那样了,使用html 做 ui ,大家都知道 使用div +css布局是一件非常容易的事情; 光说不练是假打,所以花了一个把小时尝试把winform的界面做成 webui 一: 大家都知道 winform 中有个控件叫 webBrowser 如果你不知道具体怎么用 详细看msdn 都知道了; 这里的它就是主角; 准备: 现在 我们新建一个winform项目 在上面放一个webBrowser 名称默认 停靠父窗口 在新建一个html 网页 名称 html.htm #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.moveContron1 = new MoveControns.MoveContron(this.components); this.webBrowser1 = new System.Windows.Forms.WebBrowser(); this