WinForm&&DEV知識小結

若雲發表於2014-10-20

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

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);


}


}


 

相關文章