WinForm&&DEV知识小结

--------------------------------------------------------------------------------

1、父窗体Form1中调用子窗体Form2代码:

 

Form2 fr = new Form2();

this.hide();

fr.ShowDialog(this);

 

2、子窗体的FormClosed事件代码:

private void Form2_FormClosed(object sender, FormClosedEventArgs e)

{

Login login = (Login)this.Owner;

login.Dispose();

login.Close();

}

--------------------------------------------------------------------------------

winform无边框拖动窗体

private Point mPoint = new Point();

 

private void Form1_MouseDown(object sender, MouseEventArgs e)

{

mPoint.X = e.X;

mPoint.Y = e.Y;

}

 

private void Form1_MouseMove(object sender, MouseEventArgs e)

{

if (e.Button == MouseButtons.Left)

{

Point myPosittion = MousePosition;

myPosittion.Offset(-mPoint.X, -mPoint.Y);

Location = myPosittion;

}

}

--------------------------------------------------------------------------------

读取datatable 几种方法

1for (int i = 0; i< dt.rows.count; i++)

{

    string strname = dt.rows[i]["字段名"].tostring();

}

2, foreach(datarow myrow in mydataset.tables["temp"].rows)

{

    var str = myrow[0].tostring();

}

3,foreach(datarow dr in dt.rows)

{

    object value = dr["columnsname"];

}

4,

Datatable.select("kymd>'2011-11-5' or kymd is null")

----------------------------------------------------------------------------------

datatable 合并

//前提:dt1和dt2表结构相同

foreach (DataRow dr in dt2.Rows)

dt1.Rows.Add(dr.ItemArray);

//绑定表格

dataGridView1.DataSource = dt1;

 

----------------------------------------------------------------------------------

修改datatable中的列名称

MyDt.Columns["xx"].ColumnName = "aa";

 

----------------------------------------------------------------------------------

用dictionary写键值对添加到datatable中 绑定combox显示值与属性值

//初始化下拉框值

Dictionary<string, string> dic = new Dictionary<string, string>();

dic.Add("气压", "AIRP");

dic.Add("气温", "ATMP");

dic.Add("湿度", "RHU");

dic.Add("降水", "ACCP");

dic.Add("风速", "WIN");

dic.Add("日照", "SSD");

dic.Add("地温", "GST");

dic.Add("蒸发", "ACCE");

DataTable dt = new DataTable();

dt.Columns.Add("key");

dt.Columns.Add("name");

foreach (var item in dic)

{

DataRow dr = dt.NewRow();

dr["key"] = item.Key;

dr["name"] = item.Value;

dt.Rows.Add(dr);

}

this.cmbType.DataSource = dt;

this.cmbType.DisplayMember = "key";

this.cmbType.ValueMember = "name";

 

----------------------------------------------------------------------------------

Dev

1、 如何解决单击记录整行选中的问题

 

View->OptionsBehavior->EditorShowMode 设置为:Click

 

4、如何让行只能选择而不能编辑(或编辑某一单元格)

 

(1)、View->OptionsBehavior->EditorShowMode 设置为:Click

 

(2)、View->OptionsBehavior->Editable 设置为:false

 

 

 

5、如何禁用 GridControl 中单击列弹出右键菜单

 

设置 Run Design->OptionsMenu->EnableColumnMenu 设置为:false

 

 

 

6、如何隐藏 GridControl 的 GroupPanel 表头

 

设置 Run Design->OptionsView->ShowGroupPanel 设置为:false

 

 

----------------------------------------------------------------------------------

Winfrom 与flash交互

 

//获取自定义事件

axShockwaveFlash1.FlashCall += new AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEventHandler(axShockwaveFlash1_FlashCall);

 

//鼠标点击弹出信息

public void axShockwaveFlash1_FlashCall(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEvent e)

{

XmlDocument document = new XmlDocument();

document.LoadXml(e.request);

 

XmlAttributeCollection attributes = document.FirstChild.Attributes;

string command = attributes.Item(0).InnerText;

MessageBox.Show(command);

}

 

 

 

----------------------------------------------------------------------------------

WinForm设置全局皮肤 skin

 

//设置skin皮肤全局

string path = Application.StartupPath + @"\skin\Warm\WarmColor3.ssk";

se = new Sunisoft.IrisSkin.SkinEngine();

se.SkinAllForm = true;

se.SkinFile = path;

this.StartPosition = FormStartPosition.CenterScreen;

 

修改界面图标

string iconPath = Application.StartupPath + @"\image\a.ico";

this.Icon = new Icon(iconPath);

 

 

----------------------------------------------------------------------------------

 

Winform窗体淡入淡出效果

(百度来的)

 

[System.Runtime.InteropServices.DllImport("user32.dll")]

private static extern bool AnimateWindow(IntPtr whnd, int dwtime, int dwflag);

//dwflag的取值如下

public const Int32 AW_HOR_POSITIVE = 0x00000001;

//从左到右显示

public const Int32 AW_HOR_NEGATIVE = 0x00000002;

//从右到左显示

public const Int32 AW_VER_POSITIVE = 0x00000004;

//从上到下显示

public const Int32 AW_VER_NEGATIVE = 0x00000008;

//从下到上显示

public const Int32 AW_CENTER = 0x00000010;

//若使用了AW_HIDE标志,则使窗口向内重叠,即收缩窗口;否则使窗口向外扩展,即展开窗口

public const Int32 AW_HIDE = 0x00010000;

//隐藏窗口,缺省则显示窗口

public const Int32 AW_ACTIVATE = 0x00020000;

//激活窗口。在使用了AW_HIDE标志后不能使用这个标志

public const Int32 AW_SLIDE = 0x00040000;

//使用滑动类型。缺省则为滚动动画类型。当使用AW_CENTER标志时,这个标志就被忽略

public const Int32 AW_BLEND = 0x00080000;
//透明度从高到低

 

private void MainFM_Load(object sender, EventArgs e)

{

//淡入效果

AnimateWindow(this.Handle, 3000, AW_BLEND | AW_ACTIVATE);

}

 

private void MainFM_FormClosing(object sender, FormClosingEventArgs e)

{

//淡出

AnimateWindow(this.Handle, 3000, AW_BLEND | AW_HIDE);

}

 

 

 

----------------------------------------------------------------------------------

 

Dev中的 GridControl

固定某一列始终显示

BandedGridView view = advBandedGridView1 as AdvBandedGridView;

GridBand bindSTCD = view.Bands.AddBand("站点信息");

bindSTCD.Fixed = FixedStyle.Left;

 

 

设置某列的Fixed 的属性为Left即可

 

 

----------------------------------------------------------------------------------

 

保留小数

string result = String.Format("{0:N2}", 0.55555);//N几就几位

 

注意:后面必须跟数字类型的变量不能是string等字符串

 

 

----------------------------------------------------------------------------------

指定DateTime显示时间

this.xxx.DateTime = New DateTime(2004,1,1);

 

 

 

----------------------------------------------------------------------------------

获得文件夹下的所有文件名称

string btopPath = Application.StartupPath + @"\SaveData\BTOP";

DirectoryInfo mydir = new DirectoryInfo(btopPath);

foreach (FileInfo item in mydir.GetFiles())

{

MessageBox.Show(item.FullName);

}

 

 

----------------------------------------------------------------------------------

遍历文件夹下所有文件,并读取三行,匹配xxx是个数字组成的项

private static void LoadTime(int time1, int time2)

{

string btopPath = Application.StartupPath + @"\SaveData\BTOP";

DirectoryInfo mydir = new DirectoryInfo(btopPath);

string data = "";

 

foreach (FileInfo item in mydir.GetFiles())

{

using (StreamReader sr = new StreamReader(item.FullName))

{

for (int i = 0; i < 3; i++)

{

data += sr.ReadLine() + " ";

}

string rege = @"\d{10}";

bool b = true;

foreach (Match mm in Regex.Matches(data, rege, RegexOptions.IgnoreCase))

{

 

if (b == true)

{

b = false;

time1 = int.Parse(mm.Value);

time1 = int.Parse(time1.ToString().Substring(0, 4));

}

else

{

time2 = int.Parse(mm.Value);

time2 = int.Parse(time2.ToString().Substring(0, 4));

}

}

 
 

}

 
 

//MessageBox.Show(mydir.FullName);

 
 

}

 
 

}

 

 

你可能感兴趣的:(WinForm)