c#开发windows应用程序几个小技巧
生活随笔
收集整理的這篇文章主要介紹了
c#开发windows应用程序几个小技巧
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近,我在用.net做一個c/s的項目,把我做的情況給大家說說。
datagrid是用的c1控件的c1FlexGrid,功能很多。
自定義分組和outlook形式的列頭拖拽。
textbox,combobox,checkbox是繼承.net自帶的控件,自己擴展的。
現在說一說碰到的幾個問題,及解決方法:
1.一個應用程序只能被用戶打開一次
?Process?mobj_pro?=Process.GetCurrentProcess();
????????????Process[]?mobj_proList=Process.GetProcessesByName(mobj_pro.ProcessName);
????????????if(mobj_proList.Length>1)
????????????{
????????????????MessageBox.Show("當前的應用程序已打開!",?"系統提示",?MessageBoxButtons.OK,?MessageBoxIcon.Exclamation,?MessageBoxDefaultButton.Button1);
????????????????return;
????????????}
2.一個框架窗口下只打開一個子窗口
CustomerAdd?pobj_CustomerAdd;??
????????????Form?pobj_CustomerAdd_Return=CheckIsExit("CustomerAdd");
????????????if(pobj_CustomerAdd_Return==null)
????????????{
????????????????pobj_CustomerAdd=new?CustomerAdd();
????????????????OpenSheet(pobj_CustomerAdd);
????????????}
????????????else
????????????{
????????????????OpenSheet((CustomerAdd)pobj_CustomerAdd_Return);
????????????}??
void?OpenSheet(Form?pobj_form)
????????{?
????????????pobj_form.MdiParent=this;
????????????pobj_form.Show();?
????????}
????????/**////?<summary>
????????///?判斷窗口是否存在
????????///?</summary>
????????///?<param?name="ps_windowName">窗口的名稱</param>
????????///?<returns>存在返回此窗口的實例?不存在返回null</returns>
????????Form?CheckIsExit(string?ps_windowName)
????????{
????????????for(int?i=0;i<this.MdiChildren.Length;i++)
????????????{
????????????????if(this.MdiChildren[i].Name==ps_windowName)
????????????????{
????????????????????return?this.MdiChildren[i];
????????????????}
????????????}
????????????return?null;
????????}
3.彈出式窗口顯示漸變效果
在頁面上添加一個timer控件fadeTimer,interval設為50
類的實例變量為
private m_showing=true;
在form_load中寫:
Opacity?=?0.0;
????????????Activate();
????????????Refresh();
????????????fadeTimer.Start();
????????????Refresh();????在timer控件的Tick事件中寫:
if?(m_showing)
????????????{
????????????????double?d?=?1000.0?/?fadeTimer.Interval?/?100.0;
????????????????if?(Opacity?+?d?>=?1.0)
????????????????{
????????????????????Opacity?=?1.0;
????????????????????fadeTimer.Stop();
????????????????}
????????????????else
????????????????{
????????????????????Opacity?+=?d;
????????????????}
????????????}
????????????else
????????????{
????????????????double?d?=?1000.0?/?fadeTimer.Interval?/?100.0;
????????????????if?(Opacity?-?d?<=?0.0)
????????????????{
????????????????????Opacity?=?0.0;
????????????????????fadeTimer.Stop();
????????????????}
????????????????else
????????????????{
????????????????????Opacity?-=?d;
????????????????}
????????????}
4.在控件textbox中實現按回車鍵相當于tab鍵的作用
public?class?OSTextBox:TextBox
????{
????????public?OSTextBox()
????????{
????????????
????????}
????????bool?mb_IsKeyEnter=true;
????????[
????????Category("Data"),
????????DefaultValue(true),
????????MergableProperty(false)
????????]
????????public?bool?IsKeyEnter
????????{
????????????get
????????????{
????????????????return?mb_IsKeyEnter;
????????????}
????????????set
????????????{
????????????????mb_IsKeyEnter=value;
????????????}
????????}
????????protected?override?void?OnKeyPress(KeyPressEventArgs?e)
????????{
????????????base.OnKeyPress?(e);
????????????if(mb_IsKeyEnter)
????????????{
????????????????if?(e.KeyChar?==?(char)Keys.Enter)
????????????????{
????????????????????SendKeys.Send("{Tab}");
????????????????}
????????????}
????????}
????}
還有很多東西,正在研究中,比如發票套打在c/s中的實現,用.net讀取IC卡等,等完成了再給大家共享
datagrid是用的c1控件的c1FlexGrid,功能很多。
自定義分組和outlook形式的列頭拖拽。
textbox,combobox,checkbox是繼承.net自帶的控件,自己擴展的。
現在說一說碰到的幾個問題,及解決方法:
1.一個應用程序只能被用戶打開一次
?Process?mobj_pro?=Process.GetCurrentProcess();
????????????Process[]?mobj_proList=Process.GetProcessesByName(mobj_pro.ProcessName);
????????????if(mobj_proList.Length>1)
????????????{
????????????????MessageBox.Show("當前的應用程序已打開!",?"系統提示",?MessageBoxButtons.OK,?MessageBoxIcon.Exclamation,?MessageBoxDefaultButton.Button1);
????????????????return;
????????????}
2.一個框架窗口下只打開一個子窗口
CustomerAdd?pobj_CustomerAdd;??
????????????Form?pobj_CustomerAdd_Return=CheckIsExit("CustomerAdd");
????????????if(pobj_CustomerAdd_Return==null)
????????????{
????????????????pobj_CustomerAdd=new?CustomerAdd();
????????????????OpenSheet(pobj_CustomerAdd);
????????????}
????????????else
????????????{
????????????????OpenSheet((CustomerAdd)pobj_CustomerAdd_Return);
????????????}??
void?OpenSheet(Form?pobj_form)
????????{?
????????????pobj_form.MdiParent=this;
????????????pobj_form.Show();?
????????}
????????/**////?<summary>
????????///?判斷窗口是否存在
????????///?</summary>
????????///?<param?name="ps_windowName">窗口的名稱</param>
????????///?<returns>存在返回此窗口的實例?不存在返回null</returns>
????????Form?CheckIsExit(string?ps_windowName)
????????{
????????????for(int?i=0;i<this.MdiChildren.Length;i++)
????????????{
????????????????if(this.MdiChildren[i].Name==ps_windowName)
????????????????{
????????????????????return?this.MdiChildren[i];
????????????????}
????????????}
????????????return?null;
????????}
3.彈出式窗口顯示漸變效果
在頁面上添加一個timer控件fadeTimer,interval設為50
類的實例變量為
private m_showing=true;
在form_load中寫:
Opacity?=?0.0;
????????????Activate();
????????????Refresh();
????????????fadeTimer.Start();
????????????Refresh();????在timer控件的Tick事件中寫:
if?(m_showing)
????????????{
????????????????double?d?=?1000.0?/?fadeTimer.Interval?/?100.0;
????????????????if?(Opacity?+?d?>=?1.0)
????????????????{
????????????????????Opacity?=?1.0;
????????????????????fadeTimer.Stop();
????????????????}
????????????????else
????????????????{
????????????????????Opacity?+=?d;
????????????????}
????????????}
????????????else
????????????{
????????????????double?d?=?1000.0?/?fadeTimer.Interval?/?100.0;
????????????????if?(Opacity?-?d?<=?0.0)
????????????????{
????????????????????Opacity?=?0.0;
????????????????????fadeTimer.Stop();
????????????????}
????????????????else
????????????????{
????????????????????Opacity?-=?d;
????????????????}
????????????}
4.在控件textbox中實現按回車鍵相當于tab鍵的作用
public?class?OSTextBox:TextBox
????{
????????public?OSTextBox()
????????{
????????????
????????}
????????bool?mb_IsKeyEnter=true;
????????[
????????Category("Data"),
????????DefaultValue(true),
????????MergableProperty(false)
????????]
????????public?bool?IsKeyEnter
????????{
????????????get
????????????{
????????????????return?mb_IsKeyEnter;
????????????}
????????????set
????????????{
????????????????mb_IsKeyEnter=value;
????????????}
????????}
????????protected?override?void?OnKeyPress(KeyPressEventArgs?e)
????????{
????????????base.OnKeyPress?(e);
????????????if(mb_IsKeyEnter)
????????????{
????????????????if?(e.KeyChar?==?(char)Keys.Enter)
????????????????{
????????????????????SendKeys.Send("{Tab}");
????????????????}
????????????}
????????}
????}
還有很多東西,正在研究中,比如發票套打在c/s中的實現,用.net讀取IC卡等,等完成了再給大家共享
轉載于:https://www.cnblogs.com/martinxj/archive/2004/07/23/26969.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的c#开发windows应用程序几个小技巧的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python3.7[列表] 索引切片
- 下一篇: 创建dynamics CRM clien