WinForm程序开发
2015-06-04 10:30
281 查看
WinForm程序开发
------------------------------主要页面----------------------------------
BaseForm.cs 基类,用于派生子窗口
Login.cs 登录,用于登录窗口
MainForm.cs 主页,系统主页
LoginOut.cs 注销,用于登录注销窗口
Page 文件夹,其他创业所在的目录
------------------------------入口程序----------------------------------
static class Program
{
public static Form mainForm = null;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
if (mainForm != null)
{
Application.Run(mainForm);
}
}
}
------------------------------------------------------------------
页面跳转
//实例化主画面
Program.mainForm = new MainForm();
//关闭登录画面
this.Close();
---------------------------创建基类---------------------------------------
namespace BiogasProjectClient.Page
{
partial class BaseForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// BaseForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(702, 337);
this.Name = "BaseForm";
this.ResumeLayout(false);
}
#endregion
}
}
---------------------------webBrowser控件---------------------------------------
1.调用网址
this.webBrowser1.Url = new System.Uri("http://127.0.0.1", System.UriKind.Absolute);
2.禁止右键
this.webBrowser1.IsWebBrowserContextMenuEnabled = false;
---------------------------DockPanel控件显示页面---------------------------------------
SubPage sp = new SubPage(); //子页
//DockPanel显示SubPage页面
//this.dpMain为DockPanel的控件名称
this.sp.Show(this.dpMain, WeifenLuo.WinFormsUI.Docking.DockState.Document);
---------------------------点击弹出新页面---------------------------------------
private void menu_Click(object sender, EventArgs e){
SubPage sp = new SubPage();
sp.ShowDialog(); //弹出新页面
}
---------------------------winform程序对文件的文读写操作---------------------------------------
ArrayList LineList = new ArrayList();
LineList.Add("[读写器]");
LineList.Add("固定端口=80");
LineList.Add("(如果需要可设置为01-99)");
try
{
FileStream fs = new FileStream(System.Environment.CurrentDirectory + "//HL_ICCRW.ini", FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
for (int i = 0; i < 3; i++)
{
sw.WriteLine(LineList[i]);
}
sw.Flush();
sw.Close();
fs.Close();
MessageBox.Show("COM端口设置成功!", "COM端口设置", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
catch (Exception ex)
{
MessageBox.Show("COM端口设置失败!" + Environment.NewLine + ex.Message, "设置失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw ex;
}
读出文件:
Int16 nCOM = 0;
try
{
string[] strCOM = File.ReadAllLines(System.Environment.CurrentDirectory + "//HL_ICCRW.ini");
nCOM = Convert.ToInt16(strCOM[1].Split('=')[1]);
}
catch (Exception ex)
{
nCOM = 0;
throw ex;
}
------------------------------主要页面----------------------------------
BaseForm.cs 基类,用于派生子窗口
Login.cs 登录,用于登录窗口
MainForm.cs 主页,系统主页
LoginOut.cs 注销,用于登录注销窗口
Page 文件夹,其他创业所在的目录
------------------------------入口程序----------------------------------
static class Program
{
public static Form mainForm = null;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
if (mainForm != null)
{
Application.Run(mainForm);
}
}
}
------------------------------------------------------------------
页面跳转
//实例化主画面
Program.mainForm = new MainForm();
//关闭登录画面
this.Close();
---------------------------创建基类---------------------------------------
namespace BiogasProjectClient.Page
{
partial class BaseForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// BaseForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(702, 337);
this.Name = "BaseForm";
this.ResumeLayout(false);
}
#endregion
}
}
---------------------------webBrowser控件---------------------------------------
1.调用网址
this.webBrowser1.Url = new System.Uri("http://127.0.0.1", System.UriKind.Absolute);
2.禁止右键
this.webBrowser1.IsWebBrowserContextMenuEnabled = false;
---------------------------DockPanel控件显示页面---------------------------------------
SubPage sp = new SubPage(); //子页
//DockPanel显示SubPage页面
//this.dpMain为DockPanel的控件名称
this.sp.Show(this.dpMain, WeifenLuo.WinFormsUI.Docking.DockState.Document);
---------------------------点击弹出新页面---------------------------------------
private void menu_Click(object sender, EventArgs e){
SubPage sp = new SubPage();
sp.ShowDialog(); //弹出新页面
}
---------------------------winform程序对文件的文读写操作---------------------------------------
ArrayList LineList = new ArrayList();
LineList.Add("[读写器]");
LineList.Add("固定端口=80");
LineList.Add("(如果需要可设置为01-99)");
try
{
FileStream fs = new FileStream(System.Environment.CurrentDirectory + "//HL_ICCRW.ini", FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
for (int i = 0; i < 3; i++)
{
sw.WriteLine(LineList[i]);
}
sw.Flush();
sw.Close();
fs.Close();
MessageBox.Show("COM端口设置成功!", "COM端口设置", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
catch (Exception ex)
{
MessageBox.Show("COM端口设置失败!" + Environment.NewLine + ex.Message, "设置失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw ex;
}
读出文件:
Int16 nCOM = 0;
try
{
string[] strCOM = File.ReadAllLines(System.Environment.CurrentDirectory + "//HL_ICCRW.ini");
nCOM = Convert.ToInt16(strCOM[1].Split('=')[1]);
}
catch (Exception ex)
{
nCOM = 0;
throw ex;
}
相关文章推荐
- Android自己主动化測试——CTS測试
- edmx
- 关于iWebOffice中使用变量插入到Office书签里面
- 一次业务数据处理的设计图
- Winows 10 build 10136最新截图曝光! Edge浏览器图标正式使用
- 运维常用软件
- mac pro nginx配置
- linux移植过程中近日遇到问题汇总贴
- 如何从jenkins传递测试地址到自动化脚本
- Hbase Bulk Loading与HBase API方式分析和对比
- sql常用函数分析
- [Erlang]Ets并发读写详解
- SQL Server函数——表值函数和标量函数
- [BZOJ2879][Noi2012]美食节 && 动态加边费用流
- 一张图让你学会Python
- Java的HashMap和HashTable
- 《大话设计模式》--会修电脑不会修收音机--依赖倒转原则<Depend Reverse Principal>(5)
- 选择员工要有3S能力
- [iOS]MD5加密字符串
- 2015.06.03 工作任务与心得