博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c#开发windows应用程序几个小技巧
阅读量:5277 次
发布时间:2019-06-14

本文共 2157 字,大约阅读时间需要 7 分钟。

最近,我在用.net做一个c/s的项目,把我做的情况给大家说说。
datagrid是用的c1控件的c1FlexGrid,功能很多。
c1FlexGrid1.jpg
自定义分组和outlook形式的列头拖拽。
textbox,combobox,checkbox是继承.net自带的控件,自己扩展的。
现在说一说碰到的几个问题,及解决方法:
1.一个应用程序只能被用户打开一次
None.gif
 Process mobj_pro 
=
Process.GetCurrentProcess();
None.gif            Process[] mobj_proList
=
Process.GetProcessesByName(mobj_pro.ProcessName);
None.gif            
if
(mobj_proList.Length
>
1
)
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif
{
InBlock.gif                MessageBox.Show(
"当前的应用程序已打开!""系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
InBlock.gif                
return;
ExpandedBlockEnd.gif            }
2.一个框架窗口下只打开一个子窗口
None.gif
CustomerAdd pobj_CustomerAdd;  
None.gif            Form pobj_CustomerAdd_Return
=
CheckIsExit(
"
CustomerAdd
"
);
None.gif            
if
(pobj_CustomerAdd_Return
==
null
)
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif
{
InBlock.gif                pobj_CustomerAdd
=new CustomerAdd();
InBlock.gif                OpenSheet(pobj_CustomerAdd);
ExpandedBlockEnd.gif            }
None.gif            
else
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif
{
InBlock.gif                OpenSheet((CustomerAdd)pobj_CustomerAdd_Return);
ExpandedBlockEnd.gif            }
  
None.gif
void
 OpenSheet(Form pobj_form)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif
InBlock.gif            pobj_form.MdiParent
=this;
InBlock.gif            pobj_form.Show(); 
ExpandedBlockEnd.gif        }
None.gif
ExpandedBlockStart.gifContractedBlock.gif        
/**/
/// <summary>
InBlock.gif        
/// 判断窗口是否存在
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="ps_windowName">窗口的名称</param>
ExpandedBlockEnd.gif        
/// <returns>存在返回此窗口的实例 不存在返回null</returns>
None.gif
        Form CheckIsExit(
string
 ps_windowName)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif
{
InBlock.gif            
for(int i=0;i<this.MdiChildren.Length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(this.MdiChildren[i].Name==ps_windowName)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return this.MdiChildren[i];
ExpandedSubBlockEnd.gif                }
ExpandedSubBlockEnd.gif            }
InBlock.gif            
return null;
ExpandedBlockEnd.gif        }
3.弹出式窗口显示渐变效果
在页面上添加一个timer控件fadeTimer,interval设为50
类的实例变量为
private m_showing=true;
在form_load中写:
None.gif
Opacity 
=
 
0.0
;
None.gif            Activate();
None.gif            Refresh();
None.gif            fadeTimer.Start();
None.gif            Refresh();    
在timer控件的Tick事件中写:
None.gif
if
 (m_showing)
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif
{
InBlock.gif                
double d = 1000.0 / fadeTimer.Interval / 100.0;
InBlock.gif                
if (Opacity + d >= 1.0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Opacity 
= 1.0;
InBlock.gif                    fadeTimer.Stop();
ExpandedSubBlockEnd.gif                }
InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Opacity 
+= d;
ExpandedSubBlockEnd.gif                }
ExpandedBlockEnd.gif            }
None.gif            
else
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif
{
InBlock.gif                
double d = 1000.0 / fadeTimer.Interval / 100.0;
InBlock.gif                
if (Opacity - d <= 0.0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Opacity 
= 0.0;
InBlock.gif                    fadeTimer.Stop();
ExpandedSubBlockEnd.gif                }
InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Opacity 
-= d;
ExpandedSubBlockEnd.gif                }
ExpandedBlockEnd.gif            }
4.在控件textbox中实现按回车键相当于tab键的作用
None.gif
public
 
class
 OSTextBox:TextBox
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif
{
InBlock.gif        
public OSTextBox()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
ExpandedSubBlockEnd.gif        }
InBlock.gif
InBlock.gif        
bool mb_IsKeyEnter=true;
InBlock.gif
InBlock.gif        [
InBlock.gif        Category(
"Data"),
InBlock.gif        DefaultValue(
true),
InBlock.gif        MergableProperty(
false)
InBlock.gif        ]
InBlock.gif        
public bool IsKeyEnter
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return mb_IsKeyEnter;
ExpandedSubBlockEnd.gif            }
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                mb_IsKeyEnter
=value;
ExpandedSubBlockEnd.gif            }
ExpandedSubBlockEnd.gif        }
InBlock.gif
InBlock.gif        
protected override void OnKeyPress(KeyPressEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
base.OnKeyPress (e);
InBlock.gif            
if(mb_IsKeyEnter)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (e.KeyChar == (char)Keys.Enter)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    SendKeys.Send(
"{Tab}");
ExpandedSubBlockEnd.gif                }
ExpandedSubBlockEnd.gif            }
ExpandedSubBlockEnd.gif        }
InBlock.gif
ExpandedBlockEnd.gif    }
还有很多东西,正在研究中,比如发票套打在c/s中的实现,用.net读取IC卡等,等完成了再给大家共享

转载于:https://www.cnblogs.com/martinxj/archive/2004/07/23/26969.html

你可能感兴趣的文章
JS中实现字符串和数组的相互转化
查看>>
web service和ejb的区别
查看>>
Windows Azure Cloud Service (29) 在Windows Azure发送邮件(下)
查看>>
CS61A Efficiency 笔记
查看>>
微信上传素材返回 '{"errcode":41005,"errmsg":"media data missing"}',php5.6返回
查看>>
div或者p标签单行和多行超出显示省略号
查看>>
Elasticsearch 滚动重启 必读
查看>>
Hadoop基本概念
查看>>
java.util.zip压缩打包文件总结一:压缩文件及文件下面的文件夹
查看>>
浅说 apache setenvif_module模块
查看>>
MySQL--数据插入
查看>>
重新学习python系列(二)? WTF?
查看>>
shell脚本统计文件中单词的个数
查看>>
SPCE061A学习笔记
查看>>
sql 函数
查看>>
hdu 2807 The Shortest Path 矩阵
查看>>
熟悉项目需求,要知道产品增删修改了哪些内容,才会更快更准确的在该项目入手。...
查看>>
JavaScript 变量
查看>>
java实用类
查看>>
smarty模板自定义变量
查看>>