关于用c#做桌面应用程序的几个小问题 1、我想固定我的窗体的大小,就是说用户可以最小化我的窗口,但是不能最大化,也不能拉大我的窗体,请问我该怎么做?就像QQ的登陆窗体一样。2、我想用户点击“确定”的时候,我的窗体可以最小化到windows的通知区域,(还是拿QQ举例,就是QQ登陆后的在右下角有个小企鹅的图标),我该怎么做?3、我用process类怎么才可以实现关闭打开了特定网址的那个IE浏览器。先谢谢各位DD们了、。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1 设置FormBorderStyle = FixedSingle;MaximizeBox = false;2.notifyicon 1:设置窗体属性如下:this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;this.MaximizeBox = false;this.MinimizeBox = true;2:要使用NotifyIcon,把此控件放到你的窗体上,然后参考下面的代码:bool exit=false;protected override void OnFormClosing(FormClosingEventArgs e){ base.OnFormClosing(e); if (!exit) { this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; e.Cancel = true; }}private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e){ if (this.WindowState == FormWindowState.Minimized) { this.WindowState = FormWindowState.Normal; this.ShowInTaskbar = true; } else { this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; }}private void mnuClose_Click(object sender, EventArgs e){ this.exit = true; this.Close();}3:正在想... 1 this.FormBorderStyle = FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MinimizeBox = false; 2 NotifyIcon _NotifyIcon = new NotifyIcon(); _NotifyIcon.Icon = this.Icon; _NotifyIcon.Visible = true; 3 System.Diagnostics.Process.Start("http://www.zz.ha.cn"); System.Diagnostics.Process[] _ProcessList = System.Diagnostics.Process.GetProcessesByName("IEXPLORE"); for (int i = 0; i != _ProcessList.Length; i++) { MessageBox.Show(_ProcessList[i].MainWindowTitle); //判断 //_ProcessList[i].Kill(); //关闭窗体 } 虽然MinWindowTitle比较不准确,但是仅从Process来说这个是比较好用的了。没有想到更好的办法。 1、我想固定我的窗体的大小,就是说用户可以最小化我的窗口,但是不能最大化,也不能拉大我的窗体,请问我该怎么做?就像QQ的登陆窗体一样。 form窗体有个属性的,FormBorderStyle设置一下,为FixedSingle然后最大化的属性-MaximizeBox设为false. System.Diagnostics.Process.Start("http://www.zz.ha.cn"); 3 第三个using System;using System.Collections.Generic;using System.Runtime;using System.Runtime.InteropServices;using System.Threading;using System.Diagnostics;using System.Text;namespace PM{ class Program { static void Main(string[] args) { Console.OutputEncoding = Encoding.GetEncoding(936); EWD ew = new EWD(EnumWin); Process[] ps = Process.GetProcessesByName("IEXPLORE"); foreach (Process p in ps) foreach (ProcessThread t in p.Threads) EnumThreadWindows(t.Id, ew, 0); } public static bool EnumWin(IntPtr hwnd, int lparam) { StringBuilder buff = new StringBuilder(256); IntPtr p; p = FindWindowEx(hwnd, IntPtr.Zero, "WorkerA", null); if (p == IntPtr.Zero) p = FindWindowEx(hwnd, IntPtr.Zero, "WorkerW", null); // 非浏览器窗口 if (p == IntPtr.Zero) return true; p = FindWindowEx(p, IntPtr.Zero, "ReBarWindow32", null); p = FindWindowEx(p, IntPtr.Zero, "ComboBoxEx32", null); p = FindWindowEx(p, IntPtr.Zero, "ComboBox", null); p = FindWindowEx(p, IntPtr.Zero, "Edit", null); SendMessage(p, 13, buff.Capacity, buff); Console.WriteLine("Found {0} : {1}", p, buff); return true; } public delegate bool EWD(IntPtr hwnd, int lparam); [DllImport("user32.dll")] public extern static bool EnumThreadWindows(int dwThreadId, EWD lpfn, int lParam); [DllImport("user32.dll")] public extern static IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("user32.dll", CharSet = CharSet.Auto)] public extern static int SendMessage(IntPtr hWnd, int Msg, int wParam, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lParam); }}参考 http://topic.csdn.net/t/20020716/17/878893.html C#怎样自定义流程模板,求解决方案? 如何实现类似3dsmax的命令面板?如图 怎样取得vbs的返回值 Server.MapPath问题 求C#编写服务器端控件 c#选择性备份MySql数据库 求解asp.net mvc4退出的出口是什么 难度问题。怎么注册winnt/system32/下面的com组件?????? 怎样制作安装盘!:)急急! C#编写插件求指点,有E语言源码。 DataGridView的数据怎样才能即时刷新并将已改变的数据用红色显示? 高手进:怎么获取本机所有可用的webservics
2.notifyicon
this.MaximizeBox = false;
this.MinimizeBox = true;
2:要使用NotifyIcon,把此控件放到你的窗体上,然后参考下面的代码:bool exit=false;
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
if (!exit)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
e.Cancel = true;
}
}private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
}
else
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
}private void mnuClose_Click(object sender, EventArgs e)
{
this.exit = true;
this.Close();
}3:正在想...
this.MaximizeBox = false;
this.MinimizeBox = false; 2 NotifyIcon _NotifyIcon = new NotifyIcon();
_NotifyIcon.Icon = this.Icon;
_NotifyIcon.Visible = true;
3 System.Diagnostics.Process.Start("http://www.zz.ha.cn"); System.Diagnostics.Process[] _ProcessList = System.Diagnostics.Process.GetProcessesByName("IEXPLORE"); for (int i = 0; i != _ProcessList.Length; i++)
{
MessageBox.Show(_ProcessList[i].MainWindowTitle);
//判断
//_ProcessList[i].Kill(); //关闭窗体
}
form窗体有个属性的,FormBorderStyle设置一下,为FixedSingle
然后最大化的属性-MaximizeBox设为false.
using System.Collections.Generic;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;
using System.Text;namespace PM
{
class Program
{
static void Main(string[] args)
{
Console.OutputEncoding = Encoding.GetEncoding(936); EWD ew = new EWD(EnumWin);
Process[] ps = Process.GetProcessesByName("IEXPLORE");
foreach (Process p in ps)
foreach (ProcessThread t in p.Threads)
EnumThreadWindows(t.Id, ew, 0);
} public static bool EnumWin(IntPtr hwnd, int lparam)
{
StringBuilder buff = new StringBuilder(256); IntPtr p;
p = FindWindowEx(hwnd, IntPtr.Zero, "WorkerA", null);
if (p == IntPtr.Zero)
p = FindWindowEx(hwnd, IntPtr.Zero, "WorkerW", null);
// 非浏览器窗口
if (p == IntPtr.Zero)
return true; p = FindWindowEx(p, IntPtr.Zero, "ReBarWindow32", null);
p = FindWindowEx(p, IntPtr.Zero, "ComboBoxEx32", null);
p = FindWindowEx(p, IntPtr.Zero, "ComboBox", null);
p = FindWindowEx(p, IntPtr.Zero, "Edit", null); SendMessage(p, 13, buff.Capacity, buff);
Console.WriteLine("Found {0} : {1}", p, buff); return true;
} public delegate bool EWD(IntPtr hwnd, int lparam); [DllImport("user32.dll")]
public extern static bool EnumThreadWindows(int dwThreadId, EWD lpfn, int lParam); [DllImport("user32.dll")]
public extern static IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public extern static int SendMessage(IntPtr hWnd, int Msg, int wParam, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lParam);
}
}
参考 http://topic.csdn.net/t/20020716/17/878893.html