在C#里如何重写comboBox控件的Size

crecrecre 2009-01-04 10:25:13
在帮助文档看到好像可以改变comboBox的Size属性值的,不知怎样写?
...全文
859 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
GS1T74wjwpg 2009-01-08
  • 打赏
  • 举报
回复
comboBox.size=new point(x,y)
x,y为自定义变量
yhy0611 2009-01-08
  • 打赏
  • 举报
回复
ComboBox1.Size = New Point(1, 11)
不知道行不行?
ChinaITOldMan 2009-01-08
  • 打赏
  • 举报
回复
学习
lunat 2009-01-08
  • 打赏
  • 举报
回复
mark
crecrecre 2009-01-08
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 zhaozhijun0207 的回复:]
引用 7 楼 wuyq11 的回复:
ComboBox1.Size = New Size(1, 11)




是这样的啊,我的都可以.
[/Quote]

ComboBox1.Size = New Size(150, 35) 没有改变高度。
是在VS2008上,还是VS2005上。
zhaozhijun0207 2009-01-08
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 wuyq11 的回复:]
ComboBox1.Size = New Size(1, 11)

[/Quote]


是这样的啊,我的都可以.
gsmlove 2009-01-07
  • 打赏
  • 举报
回复
mark
dayizhixiaotutu 2009-01-07
  • 打赏
  • 举报
回复
这个是自定义控件 你在你的项目里 创建一个类ComboBoxDraw 让他继承ComboBox
这些就是那个自定义控件的代码
public class ComboBoxDraw : ComboBox
{
protected override void WndProc(ref System.Windows.Forms.Message m)
{
base.WndProc(ref m);

//拦截系统消息,获得当前控件进程以便重绘。
if (m.Msg == 0xf || m.Msg == 0x133)
{
this.DrawSize();
}
}
private void DrawSize()
{
this.Size = new System.Drawing.Size(20, 50);
}
}
然后在你的工具箱里 会有这个自定义控件 就跟windows的自定义控件一样 你把他拽到你的form上就好了
crecrecre 2009-01-06
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 dayizhixiaotutu 的回复:]
C# code public class ComboBoxDraw : ComboBox
{
protected override void WndProc(ref System.Windows.Forms.Message m)
{
base.WndProc(ref m);

//拦截系统消息,获得当前控件进程以便重绘。
if (m.Msg == 0xf || m.Msg == 0x133)
{
this.DrawSize();
}
}
private void DrawSize()

[/Quote]



public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
我把代码放在这个位置上;没有变化,请问应该放在什么地方?

dayizhixiaotutu 2009-01-06
  • 打赏
  • 举报
回复
 public class ComboBoxDraw : ComboBox
{
protected override void WndProc(ref System.Windows.Forms.Message m)
{
base.WndProc(ref m);

//拦截系统消息,获得当前控件进程以便重绘。
if (m.Msg == 0xf || m.Msg == 0x133)
{
this.DrawSize();
}
}
private void DrawSize()
{
this.Size = new System.Drawing.Size(20, 50);
}
}
crecrecre 2009-01-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 wuyq11 的回复:]
ComboBox1.Size = New Size(1, 1)
http://www.cnblogs.com/dominic/archive/2006/07/28/461857.html
[/Quote]

“ComboBox1.Size = New Size(1, 1)”试了不成。

“http://www.cnblogs.com/dominic/archive/2006/07/28/461857.html”这个好像是在dropdown事件的情况下。

我希望的是,在设计时,能否改变comboboxBox的size.height;或是变一段简单的代码来改变它的高度;
在一个表单里有comboBox,textBox(宋体,12)在同一行,出现高度不一样的现象怎么处理?
wuyq11 2009-01-06
  • 打赏
  • 举报
回复
crecrecre 2009-01-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 s000rd 的回复:]
直接修改字号吧,那样最简单。
[/Quote]

在一个表单里有comboBox,textBox,maskedTextBox都是‘宋体,12’,怎样调整它们的高度一样高?
crecrecre 2009-01-04
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 javakiki 的回复:]
重写控件
写一个类继承comboBox,然后把属性size赋值就可以了。
[/Quote]

怎么写?
javakiki 2009-01-04
  • 打赏
  • 举报
回复
重写控件
写一个类继承comboBox,然后把属性size赋值就可以了。
s000rd 2009-01-04
  • 打赏
  • 举报
回复
直接修改字号吧,那样最简单。
Hertz_liu 2009-01-04
  • 打赏
  • 举报
回复
comboBox不能通过直接设置属性来改变他的Size吗?
winform的没做过,但是DropDownList是可以的
cheng_er 2009-01-04
  • 打赏
  • 举报
回复
没做过,帮顶
这篇文章中我们重点需要实现的是(3)、(4)两项功能,下面我们来介绍具体实现的方法。 第一步,实现ImageComboBoxItem类。 要实现显示图标,当然要给每个项添加与图标相关的信息了,ImageComboBoxItem类应该包括以下内容:文本(Text)、缩进的级别(Level)、图标的索引(ImageIndex、ImageKey),用户数据(Tag)。ImageComboBoxItem类实现了ISerializable接口,实现自定义序列化。ImageComboBoxItem类的类视图如下: 图3 ImageComboxItem类视图 ImageComboBoxItem类的代码如下: [Serializable] [DefaultProperty("Text")] [TypeConverter( typeof(ExpandableObjectConverter))] public class ImageComboBoxItem : IDisposable, ISerializable ...{ Fields#region Fields private ImageComboBox _imageComboBox; private string _text = "ImageComboBoxItem"; private ImageComboBoxItemImageIndexer _imageIndexer; private object _tag; private int _level; #endregion Constructors#region Constructors public ImageComboBoxItem() ...{ } public ImageComboBoxItem(string text) : this(text, -1, 0) ...{ } public ImageComboBoxItem( string text, int imageIndex) : this(text, imageIndex, 0) ...{ } public ImageComboBoxItem( string text, string imageKey) : this(text, imageKey, 0) ...{ } public ImageComboBoxItem( string text, int imageIndex, int level) : this() ...{ _text = text; ImageIndexer.Index = imageIndex; _level = level; } public ImageComboBoxItem( string text, string imageKey, int level) : this() ...{ _text = text; ImageIndexer.Key = imageKey; _level = level; } protected ImageComboBoxItem( SerializationInfo info, StreamingContext context) : this() ...{ Deserialize(info, context); } #endregion Properties#region Properties [Localizable(true)]
/* API精灵 FOR C# 开始设计日期 2004.03.06 设计目的:简单快速对C#中使用的API函数进行查询,并给出调用代码 设计进度: 2004.03.09 完成对的查询功能,包括 代码调用,中文注释,所需的DLL库,与C#中函数对应关系 2004.03.10 0:48:52 完成了用StringBuilder数组对原ComboBox的替换,可以使程序不用从新读取数据库就可以刷新修改后的信息! 2004.03.10 18:00:00 完成了用ArrayList对StringBuilder数组的替换节省2M内存 2004.03.11 21:10:15 完成滚动字幕的设置,启用了一个TIMER控件,然后设置时间,删除字符串的第一个字母已达到滚动效果! 2004.03.11 22:02:00 改正更新时出现空值出错问题,新填函数isnull 2004.03.12 13:22:08 完成关键字高亮显示 高亮显示函数 mykeywords 2004.03.12 22:08:20 加强了高亮显示函数 mykeywords的功能,使其能识别不同的关键字并显示不同的颜色 2004.03.14 01:40:00 完成对CONST的查询,并且增加了 mykeywords1函数,使其关键字显示性能提高 2004.03.14 13:12:00 添加了提示信息,提示信息设置在函数 mytips() 中 2004.03.15 21:51:20 更改数据库和WINAPI.TXT路径为程序运行路径 2004.03.15 22:31:50 添加了鼠标右键信息 2004.03.15 23.23:30 添加了数据库密码 2004.03.16 23:24:30 添加了版权信息以及相应提示 */ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.OleDb; using System.Runtime.InteropServices; using System.IO; namespace API精灵 { /// /// Form1 的摘要说明。 /// 这个版本没有使用oleDbDataAdapter+DataSet对数据进行存取,而是使用的OleDbCommand +OleDbDataReader 的形式。 /// 主要是想试验一下不用oleDbDataAdapter+DataSet的数据存取速度。 /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.Button button4; private System.Windows.Forms.TextBox mysearch; private System.Windows.Forms.ListBox tiplist; private System.Windows.Forms.ComboBox select_type; private System.Windows.Forms.TextBox dlltext; /// /// 必需的设计器变量。 /// //自定义变量 private ArrayList fundll = new ArrayList();//保存读取出来的DLL内容 private ArrayList funtips = new ArrayList();//保存读取出来的中文提示信息 private ArrayList funcode = new ArrayList();//保存读取出来的C#调用代码 private ArrayList funmat = new ArrayList();//保存读取出来的C#对应函数 private ArrayList funwin9x = new ArrayList();//保存读取出来的WIN9X private ArrayList funwin2k = new ArrayList();//保存读取出来的WIN2K private int nowselect = 0; private string oldscoll_text; private int nowtypeselect = 0; private string nowpath = @System.Environment.CurrentDirectory+@"\"; private string dbpassword = "ling_feng_work"; public string myConnstr; public OleDbConnection myconn ;//创建一个新连接 private string mysql ;//查询语句 private string sql_update; private System.Windows.Forms.RichTextBox tipsmemo; private System.Windows.Forms.TextBox mat_text; private OleDbCommand mycommand = new OleDbCommand(); private System.Windows.Forms.RichTextBox codememo; private System.Windows.Forms.GroupBox groupBox4; private System.Windows.Forms.CheckBox win9x; private System.Windows.Forms.GroupBox groupBox5; private System.Windows.Forms.CheckBox win2k; private System.Windows.Forms.CheckBox e_add; private System.Windows.Forms.CheckBox e_modify; private System.Windows.Forms.Button b_modify; private System.Windows.Forms.Button b_add; private System.Windows.Forms.Timer timer1; private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.ContextMenu mypop; private System.Windows.Forms.MenuItem menuItem1; private System.ComponentModel.IContainer components; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// /// 清理所有正在使用的资源。 /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); this.button1 = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.tiplist = new System.Windows.Forms.ListBox(); this.select_type = new System.Windows.Forms.ComboBox(); this.mat_text = new System.Windows.Forms.TextBox(); this.mysearch = new System.Windows.Forms.TextBox(); this.dlltext = new System.Windows.Forms.TextBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.tipsmemo = new System.Windows.Forms.RichTextBox(); this.mypop = new System.Windows.Forms.ContextMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.codememo = new System.Windows.Forms.RichTextBox(); this.b_modify = new System.Windows.Forms.Button(); this.b_add = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.win2k = new System.Windows.Forms.CheckBox(); this.win9x = new System.Windows.Forms.CheckBox(); this.groupBox5 = new System.Windows.Forms.GroupBox(); this.e_add = new System.Windows.Forms.CheckBox(); this.e_modify = new System.Windows.Forms.CheckBox(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); this.groupBox4.SuspendLayout(); this.groupBox5.SuspendLayout(); this.SuspendLayout(); // // button1 // this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button1.Location = new System.Drawing.Point(224, 395); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 24); this.button1.TabIndex = 10; this.button1.Text = "关 于"; this.button1.Click += new System.EventHandler(this.button1_Click); // // groupBox1 // this.groupBox1.Controls.Add(this.tiplist); this.groupBox1.Controls.Add(this.select_type); this.groupBox1.Controls.Add(this.mat_text); this.groupBox1.Controls.Add(this.mysearch); this.groupBox1.Controls.Add(this.dlltext); this.groupBox1.Location = new System.Drawing.Point(8, 8); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(200, 168); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; this.groupBox1.Text = "API查询"; // // tiplist // this.tiplist.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tiplist.ItemHeight = 12; this.tiplist.Location = new System.Drawing.Point(8, 43); this.tiplist.Name = "tiplist"; this.tiplist.Size = new System.Drawing.Size(184, 110); this.tiplist.TabIndex = 1; this.tiplist.Visible = false; this.tiplist.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tiplist_KeyDown); this.tiplist.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tiplist_KeyPress); this.tiplist.DoubleClick += new System.EventHandler(this.tiplist_DoubleClick); this.tiplist.MouseUp += new System.Windows.Forms.MouseEventHandler(this.tiplist_MouseUp); this.tiplist.MouseLeave += new System.EventHandler(this.tiplist_MouseLeave); this.tiplist.SelectedIndexChanged += new System.EventHandler(this.tiplist_SelectedIndexChanged); // // select_type // this.select_type.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.select_type.Items.AddRange(new object[] { "API函数查询", "常量定义查询"}); this.select_type.Location = new System.Drawing.Point(8, 61); this.select_type.Name = "select_type"; this.select_type.Size = new System.Drawing.Size(184, 20); this.select_type.TabIndex = 2; this.select_type.SelectedIndexChanged += new System.EventHandler(this.select_type_SelectedIndexChanged); // // mat_text // this.mat_text.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.mat_text.Location = new System.Drawing.Point(8, 134); this.mat_text.Name = "mat_text"; this.mat_text.Size = new System.Drawing.Size(184, 21); this.mat_text.TabIndex = 4; this.mat_text.Text = "C#对应函数:"; this.mat_text.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mat_text_MouseDown); // // mysearch // this.mysearch.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.mysearch.Location = new System.Drawing.Point(8, 24); this.mysearch.Name = "mysearch"; this.mysearch.Size = new System.Drawing.Size(184, 21); this.mysearch.TabIndex = 0; this.mysearch.Text = ""; this.mysearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.mysearch_KeyDown); this.mysearch.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mysearch_MouseDown); this.mysearch.TextChanged += new System.EventHandler(this.mysearch_TextChanged); // // dlltext // this.dlltext.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.dlltext.Location = new System.Drawing.Point(8, 97); this.dlltext.Name = "dlltext"; this.dlltext.Size = new System.Drawing.Size(184, 21); this.dlltext.TabIndex = 3; this.dlltext.Text = ""; this.dlltext.TextChanged += new System.EventHandler(this.dlltext_TextChanged); // // groupBox2 // this.groupBox2.Controls.Add(this.tipsmemo); this.groupBox2.Location = new System.Drawing.Point(216, 8); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(200, 168); this.groupBox2.TabIndex = 2; this.groupBox2.TabStop = false; this.groupBox2.Text = "函数注释"; // // tipsmemo // this.tipsmemo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tipsmemo.ContextMenu = this.mypop; this.tipsmemo.Location = new System.Drawing.Point(8, 16); this.tipsmemo.Name = "tipsmemo"; this.tipsmemo.Size = new System.Drawing.Size(184, 144); this.tipsmemo.TabIndex = 0; this.tipsmemo.Text = ""; this.tipsmemo.MouseEnter += new System.EventHandler(this.richTextBox1_MouseEnter); // // mypop // this.mypop.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.Text = "复制信息"; this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click); // // groupBox3 // this.groupBox3.Controls.Add(this.codememo); this.groupBox3.Location = new System.Drawing.Point(8, 221); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(408, 168); this.groupBox3.TabIndex = 3; this.groupBox3.TabStop = false; this.groupBox3.Text = "代码调用"; // // codememo // this.codememo.ContextMenu = this.mypop; this.codememo.Location = new System.Drawing.Point(8, 16); this.codememo.Name = "codememo"; this.codememo.Size = new System.Drawing.Size(392, 144); this.codememo.TabIndex = 0; this.codememo.Text = ""; this.codememo.TextChanged += new System.EventHandler(this.codememo_TextChanged); // // b_modify // this.b_modify.Enabled = false; this.b_modify.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.b_modify.Location = new System.Drawing.Point(120, 395); this.b_modify.Name = "b_modify"; this.b_modify.Size = new System.Drawing.Size(75, 24); this.b_modify.TabIndex = 4; this.b_modify.Text = "修改信息"; this.b_modify.Click += new System.EventHandler(this.button2_Click); // // b_add // this.b_add.Enabled = false; this.b_add.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.b_add.Location = new System.Drawing.Point(16, 395); this.b_add.Name = "b_add"; this.b_add.Size = new System.Drawing.Size(75, 24); this.b_add.TabIndex = 5; this.b_add.Text = "添加新项"; // // button4 // this.button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button4.Location = new System.Drawing.Point(328, 395); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(75, 24); this.button4.TabIndex = 6; this.button4.Text = "退 出"; this.button4.Click += new System.EventHandler(this.button4_Click); // // groupBox4 // this.groupBox4.Controls.Add(this.win2k); this.groupBox4.Controls.Add(this.win9x); this.groupBox4.Location = new System.Drawing.Point(8, 176); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(200, 40); this.groupBox4.TabIndex = 11; this.groupBox4.TabStop = false; // // win2k // this.win2k.Location = new System.Drawing.Point(104, 11); this.win2k.Name = "win2k"; this.win2k.Size = new System.Drawing.Size(80, 24); this.win2k.TabIndex = 1; this.win2k.Text = "支持win2k"; // // win9x // this.win9x.Location = new System.Drawing.Point(16, 11); this.win9x.Name = "win9x"; this.win9x.TabIndex = 0; this.win9x.Text = "支持win9x"; // // groupBox5 // this.groupBox5.Controls.Add(this.e_add); this.groupBox5.Controls.Add(this.e_modify); this.groupBox5.Location = new System.Drawing.Point(216, 176); this.groupBox5.Name = "groupBox5"; this.groupBox5.Size = new System.Drawing.Size(200, 40); this.groupBox5.TabIndex = 12; this.groupBox5.TabStop = false; // // e_add // this.e_add.Location = new System.Drawing.Point(112, 10); this.e_add.Name = "e_add"; this.e_add.Size = new System.Drawing.Size(80, 24); this.e_add.TabIndex = 5; this.e_add.Text = "允许添加"; this.e_add.CheckedChanged += new System.EventHandler(this.e_add_CheckedChanged); // // e_modify // this.e_modify.Location = new System.Drawing.Point(16, 10); this.e_modify.Name = "e_modify"; this.e_modify.Size = new System.Drawing.Size(76, 24); this.e_modify.TabIndex = 4; this.e_modify.Text = "允许修改"; this.e_modify.CheckedChanged += new System.EventHandler(this.e_modify_CheckedChanged); // // timer1 // this.timer1.Interval = 500; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(424, 429); this.Controls.Add(this.groupBox5); this.Controls.Add(this.groupBox4); this.Controls.Add(this.button4); this.Controls.Add(this.b_add); this.Controls.Add(this.b_modify); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox1); this.Controls.Add(this.button1); this.Controls.Add(this.groupBox2); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "API精灵FOR C#"; this.Load += new System.EventHandler(this.Form1_Load); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox3.ResumeLayout(false); this.groupBox4.ResumeLayout(false); this.groupBox5.ResumeLayout(false); this.ResumeLayout(false); } #endregion /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { Application.Run(new Form1()); } [DllImport("user32.dll", EntryPoint="ShowWindow")] public static extern int ShowWindow ( int hwnd, int nCmdShow ); private void button1_Click(object sender, System.EventArgs e) { AboutForm myabout = new AboutForm(); myabout.ShowDialog(); } /// /// 填写mysearch中的内容。 /// private void search_comp() { if (tiplist.SelectedIndex>-1) mysearch.Text = tiplist.SelectedItem.ToString(); tiplist.Visible = false ; mysearch.Select(); } /// /// 自动填写提示内容。 /// private void autocomp() { if (tiplist.SelectedIndex>-1) try { if (this.nowtypeselect==0) //================查询函数 { this.nowselect = tiplist.SelectedIndex; dlltext.Text = fundll[tiplist.SelectedIndex].ToString();//else tipsmemo.Text = funtips[tiplist.SelectedIndex].ToString(); codememo.Text = funcode[tiplist.SelectedIndex].ToString(); mat_text.Text = funmat[tiplist.SelectedIndex].ToString(); this.oldscoll_text = mat_text.Text; if (funwin9x[tiplist.SelectedIndex].ToString()==("Yes")) win9x.Checked=true; else win9x.Checked=false; if (funwin2k[tiplist.SelectedIndex].ToString()==("Yes")) win2k.Checked=true; else win2k.Checked=false; //滚动文字 if (mat_text.TextLength>30) timer1.Enabled = true; else timer1.Enabled = false; } else { dlltext.Text = ""; tipsmemo.Text = ""; codememo.Text = ""; win9x.Checked = false; win2k.Checked = false; } //******************** if (this.nowtypeselect==1) { this.nowselect = tiplist.SelectedIndex; codememo.Text = funcode[tiplist.SelectedIndex].ToString(); } //******************** //================= } catch { dlltext.Text = "没有找到相应连接库"; tipsmemo.Text = "没有找到相应提示"; codememo.Text = "没有找到相应调用代码"; mat_text.Text = "没有找到相应C#函数"; } } // /// /// 手动释放一些内存。 /// private void mydisp() { tipsmemo.Clear(); codememo.Clear(); tiplist.Items.Clear(); // ===== fundll.Clear();//保存读取出来的DLL内容 funtips.Clear();//保存读取出来的中文提示信息 funcode.Clear();//保存读取出来的C#调用代码 funmat.Clear();//保存读取出来的C#对应函数 funwin9x.Clear();//保存读取出来的WIN9X funwin2k.Clear();//保存读取出来的WIN2K } private void mysearch_TextChanged(object sender, System.EventArgs e) { tiplist.Visible = true ; //自动完成功能。 tiplist.SelectedIndex = (tiplist.FindString(mysearch.Text,-1)) ;//加上这句,保证TIPLIST跟着自动变化 nowselect = tiplist.SelectedIndex; autocomp(); //设置提示信息 mytips(); } private void mysearch_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if ((e.KeyCode == Keys.Down) || (e.KeyCode == Keys.Up)) tiplist.Focus(); if (e.KeyCode == Keys.Enter) { search_comp(); if (this.nowtypeselect==0) mykeyword(); if (this.nowtypeselect==1) mykeyword1(); } if (e.KeyCode == Keys.Escape) { tiplist.Visible = false ; } } private void tiplist_MouseLeave(object sender, System.EventArgs e) { } private void tiplist_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { } private void tiplist_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.search_comp(); if (this.nowtypeselect==0) mykeyword(); else mykeyword1(); } if (e.KeyCode == Keys.Escape) { tiplist.Visible = false ; } } private void tiplist_DoubleClick(object sender, System.EventArgs e) { this.search_comp(); if (this.nowtypeselect==0) mykeyword(); else mykeyword1(); } private void Form1_Load(object sender, System.EventArgs e) { //初始化数据库 initdatabase(); //MessageBox.Show(this,"欢迎使用 共享版\n 本版对使用功能上略有限制\n 且不提供数据库更新!\n 如想获得更多信息请与我联系。\n dong_teng@tom.com","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); select_type.SelectedIndex = 0; AboutForm myabout = new AboutForm(); myabout.ShowDialog(); } // private void mytips() { //设置提示信息 if ((this.nowselect>-1)&(this.nowtypeselect==0)) { toolTip1.SetToolTip(this.dlltext,"所在动态连接库: "+this.fundll[this.nowselect].ToString()); toolTip1.SetToolTip(this.mat_text,"在C#中对应的函数: "+this.funmat[this.nowselect].ToString()); toolTip1.SetToolTip(this.codememo,"函数 "+this.tiplist.SelectedItem.ToString()+" 在C#中的调用代码,可以手动修改"); toolTip1.SetToolTip(this.tipsmemo,"函数 "+this.tiplist.SelectedItem.ToString()+" 的注释信息,可以手动修改"); } else if ((this.nowselect>-1)&(this.nowtypeselect==1)) { toolTip1.SetToolTip(this.codememo,"常量 "+this.tiplist.SelectedItem.ToString()+" 在C#中的调用代码"); toolTip1.SetToolTip(this.dlltext,"没有相关信息"); toolTip1.SetToolTip(this.mat_text,"没有相关信息"); toolTip1.SetToolTip(this.tipsmemo,"没有相关信息"); } } // private void initdatabase() { string dbpath = @nowpath+"winapi.mdb"; tiplist.Items.Clear(); //@"Provider=Microsoft.Jet.OleDB.4.0;Data Source="+dbpath+";User Id=admin;Password="+this.dbpassword ; //"Provider=Microsoft.Jet.OleDB.4.0;Data Source=your mdb filename;Jet OLEDB:Database Password='pass'" ; this.myConnstr = @"Provider=Microsoft.Jet.OleDB.4.0;Data Source="+dbpath+";User Id=admin;Jet OLEDB:Database Password="+this.dbpassword ; this.myconn= new OleDbConnection(myConnstr); mysql= @"select Fun_name,Fun_dll,Fun_tips,Fun_code,Fun_com,win9x,win2k from winapi"; using(myconn) { myconn.Open(); // if (myconn.State.ToString() == "Open") MessageBox.Show("打开成功!"); //数据处理 // OleDbCommand mycommand = new OleDbCommand(mysql,myconn); mycommand.CommandText = mysql; mycommand.Connection = myconn; OleDbDataReader myreader = mycommand.ExecuteReader(); int i=0; while (myreader.Read()) { tiplist.Items.Add(myreader["Fun_name"]); fundll.Add(myreader["fun_dll"].ToString()); funtips.Add(myreader["fun_tips"].ToString()); funcode.Add(myreader["fun_code"].ToString()); funmat.Add(myreader["fun_com"].ToString()); funwin9x.Add(myreader["win9x"].ToString()); funwin2k.Add(myreader["win2k"].ToString()); i++; } myconn.Close(); myreader.Close(); } } //更新缓存 private void memo_update() { fundll[nowselect] = dlltext.Text; funtips[nowselect] = this.tipsmemo.Text; funcode[nowselect] = this.codememo.Text; funmat[nowselect] = this.mat_text.Text; if (win9x.Checked) funwin9x[nowselect]="Yes" ;else funwin9x[nowselect]="No"; if (win2k.Checked) funwin2k[nowselect]="Yes" ;else funwin2k[nowselect]="No"; } // private void oleDbConnection1_InfoMessage(object sender, System.Data.OleDb.OleDbInfoMessageEventArgs e) { } //==============从WINAPI.TXT读取CONST并拆分 private void mysplip() { //string dbpath = @System.Environment.CurrentDirectory+@"\winapi.mdb"; string filename =@nowpath +"winapi.txt"; string nextline; tiplist.Items.Clear(); StreamReader sr = new StreamReader(filename); while ((nextline = sr.ReadLine())!=null) { if (nextline.StartsWith("public const")) { string[] ss = nextline.Split('='); tiplist.Items.Add(ss[0].Substring(16).Trim()); funcode.Add(nextline); } } sr.Close(); } //============================== private void select_type_SelectedIndexChanged(object sender, System.EventArgs e) { if (select_type.SelectedIndex != this.nowtypeselect) { this.mydisp(); switch (select_type.SelectedIndex) { case 0:initdatabase();this.nowtypeselect=select_type.SelectedIndex;break; case 1:mysplip();this.nowtypeselect=select_type.SelectedIndex;this.dlltext.Clear();this.mat_text.Clear();break; } isenable(this.nowtypeselect); } } private void dlltext_TextChanged(object sender, System.EventArgs e) { } private void richTextBox1_MouseEnter(object sender, System.EventArgs e) { tiplist.Visible = false ; } private void mysearch_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { tiplist.Visible = false ; mysearch.Focus(); } private void tiplist_SelectedIndexChanged(object sender, System.EventArgs e) { autocomp(); } /// /// 修改内容。 /// private void fun_update() { using(myconn) { myconn.ConnectionString = myConnstr; myconn.Open(); try { //if (myconn.State.ToString() == "Open") MessageBox.Show("打开成功!"); isnull();//判断是否有无效值 string str_win9x,str_win2k; if (win9x.Checked) str_win9x = "Yes" ; else str_win9x = "No"; if (win2k.Checked) str_win2k = "Yes" ; else str_win2k = "No"; sql_update = "update winapi set Fun_dll = '"+dlltext.Text+"'"+" , Fun_tips = '"+tipsmemo.Text+"'"+" , Fun_code = '"+codememo.Text+"'"+" , Fun_com ='"+mat_text.Text+"' "; sql_update +=" , win9x = '" + str_win9x +"' " + ", win2k = '" + str_win2k+"' "; sql_update +=" where Fun_name ='"+ mysearch.Text+"'"; mycommand.Connection = myconn; mycommand.CommandText = sql_update; mycommand.ExecuteNonQuery(); myconn.Close(); memo_update(); MessageBox.Show(this,"恭喜!更新成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); } catch { // tipsmemo.Text = sql_update; MessageBox.Show("没有找到相应记录,更新失败!"); } } } //判断是更新的部分是否有效(不能为空) private void isnull() { if (this.mat_text.Text=="") this.mat_text.Text="没有相关信息"; if (this.codememo.Text=="") this.codememo.Text="没有相关信息"; if (this.tipsmemo.Text=="") this.tipsmemo.Text="没有相关信息"; if (this.dlltext.Text=="") this.dlltext.Text="没有相关信息"; } //关键字高亮显示 private void mykeyword() { string[] keywords = new string[5]; keywords[0]=mysearch.Text; keywords[1]="string"; keywords[2]="ref"; keywords[3]="int"; keywords[4]="static extern"; for(int i=0;i0) { index++; switch(i) { case 0: codememo.SelectionColor = Color.Red;break; case 1: codememo.SelectionColor = Color.Green;break; case 2: codememo.SelectionColor = Color.Brown;break; case 3: codememo.SelectionColor = Color.Blue;break; case 4: codememo.SelectionColor = Color.Green;break; //default:codememo.SelectionColor = Color.Blue;break; } } } } // //CONST中关键字高亮显示 private void mykeyword1() { string[] keywords = new string[5]; keywords[0]=mysearch.Text; keywords[1]="="; keywords[2]="0"; keywords[3]="int"; keywords[4]="const"; for(int i=0;i0) { index++; switch(i) { case 0: codememo.SelectionColor = Color.Red;break; case 1: codememo.SelectionColor = Color.Blue;break; case 2: codememo.SelectionColor = Color.Green;break; case 3: codememo.SelectionColor = Color.Blue;break; case 4: codememo.SelectionColor = Color.Green;break; //default:codememo.SelectionColor = Color.Blue;break; } if (index>codememo.TextLength) break; } } } // private void button2_Click(object sender, System.EventArgs e) { this.fun_update(); } private void isenable(int i_temp) { if (i_temp==0) { win9x.Enabled=true; win2k.Enabled=true; e_modify.Enabled=true; e_add.Enabled=true; b_modify.Enabled=true; b_add.Enabled=true; } else { win9x.Enabled=false; win2k.Enabled=false; e_modify.Enabled=false; e_add.Enabled=false; b_modify.Enabled=false; b_add.Enabled=false; } } private void button4_Click(object sender, System.EventArgs e) { Application.Exit(); } private void e_modify_CheckedChanged(object sender, System.EventArgs e) { if (e_modify.Checked) b_modify.Enabled = true; else b_modify.Enabled = false; } private void e_add_CheckedChanged(object sender, System.EventArgs e) { if (e_add.Checked) b_add.Enabled = true; else b_add.Enabled = false; } private void timer1_Tick(object sender, System.EventArgs e) { if (this.mat_text.TextLength>0) mat_text.Text = mat_text.Text.Remove(0,1); else mat_text.Text = oldscoll_text; } private void mat_text_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { timer1.Enabled = false ; mat_text.Text = oldscoll_text; } private void codememo_TextChanged(object sender, System.EventArgs e) { } private void tiplist_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { } private void menuItem1_Click(object sender, System.EventArgs e) { Control ct = this.ActiveControl; string temp = ct.Text; Clipboard.SetDataObject(temp); } private void menuItem2_Click(object sender, System.EventArgs e) { } } }
一个关于C#写的酒店管理系统。。 using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace 酒店管理系统 { public class ClientConsume : 医院管理系统.ParentForm { public static string RZid;//入住单编号 private System.Data.SqlClient.SqlConnection sqlConnection1; private 酒店管理系统.DataSet2 dataSet21; private System.Windows.Forms.Label label4; private System.Windows.Forms.TextBox txt4; private System.Windows.Forms.TextBox txt5; private System.Windows.Forms.Label label5; private System.Windows.Forms.TextBox txt6; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label8; private System.Windows.Forms.ComboBox cmb1; private System.Windows.Forms.ComboBox cmb2; private System.Windows.Forms.Button btnSelect; private System.Windows.Forms.MonthCalendar calen1; private System.Data.SqlClient.SqlCommand sqlSelectCommand1; private System.Data.SqlClient.SqlCommand sqlInsertCommand1; private System.Data.SqlClient.SqlCommand sqlUpdateCommand1; private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;//保存从入住单中选择得到的客人入住单号 private System.ComponentModel.IContainer components = null; public ClientConsume() { // 该调用是 Windows 窗体设计器所必需的。 InitializeComponent(); // TODO: 在 InitializeComponent 调用后添加任何初始化 } /// /// 清理所有正在使用的资源。 /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region 设计器生成的代码 /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ClientConsume)); this.sqlConnection1 = new System.Data.SqlClient.SqlConnection(); this.dataSet21 = new 酒店管理系统.DataSet2(); this.label4 = new System.Windows.Forms.Label(); this.txt4 = new System.Windows.Forms.TextBox(); this.txt5 = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); this.txt6 = new System.Windows.Forms.TextBox(); this.label6 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.label8 = new System.Windows.Forms.Label(); this.cmb1 = new System.Windows.Forms.ComboBox(); this.cmb2 = new System.Windows.Forms.ComboBox(); this.btnSelect = new System.Windows.Forms.Button(); this.calen1 = new System.Windows.Forms.MonthCalendar(); this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); this.groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataSet21)).BeginInit(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Name = "groupBox1"; // // txt2 // this.txt2.Name = "txt2"; // // label1 // this.label1.Name = "label1"; this.label1.Text = "消费内容"; // // btnSearch // this.btnSearch.Name = "btnSearch"; this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click); // // txt1 // this.txt1.Name = "txt1"; // // label2 // this.label2.Name = "label2"; this.label2.Text = "入住单号"; // // txt3 // this.txt3.Name = "txt3"; this.txt3.Visible = false; // // label3 // this.label3.Name = "label3"; this.label3.Visible = false; // // toolBar1 // this.toolBar1.Name = "toolBar1"; this.toolBar1.Size = new System.Drawing.Size(728, 41); // // dataGrid1 // this.dataGrid1.DataMember = "帐单明细"; this.dataGrid1.DataSource = this.dataSet21; this.dataGrid1.Name = "dataGrid1"; this.dataGrid1.Size = new System.Drawing.Size(728, 240); // // groupBox2 // this.groupBox2.Controls.Add(this.btnSelect); this.groupBox2.Controls.Add(this.cmb1); this.groupBox2.Controls.Add(this.txt4); this.groupBox2.Controls.Add(this.label4); this.groupBox2.Controls.Add(this.txt5); this.groupBox2.Controls.Add(this.label5); this.groupBox2.Controls.Add(this.txt6); this.groupBox2.Controls.Add(this.label6); this.groupBox2.Controls.Add(this.label7); this.groupBox2.Controls.Add(this.label8); this.groupBox2.Controls.Add(this.cmb2); this.groupBox2.Location = new System.Drawing.Point(0, 336); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(728, 160); // // da1 // this.da1.DeleteCommand = this.sqlDeleteCommand1; this.da1.InsertCommand = this.sqlInsertCommand1; this.da1.SelectCommand = this.sqlSelectCommand1; this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping("Table", "帐单明细", new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping("帐单编号", "帐单编号"), new System.Data.Common.DataColumnMapping("入住单号", "入住单号"), new System.Data.Common.DataColumnMapping("消费内容", "消费内容"), new System.Data.Common.DataColumnMapping("消费金额", "消费金额"), new System.Data.Common.DataColumnMapping("消费时间", "消费时间"), new System.Data.Common.DataColumnMapping("备注", "备注")})}); this.da1.UpdateCommand = this.sqlUpdateCommand1; // // sqlConnection1 // this.sqlConnection1.ConnectionString = "Data Source=.\\sqlexpress;Initial Catalog=hotelbook;Integrated Security=True"; // // dataSet21 // this.dataSet21.DataSetName = "DataSet2"; this.dataSet21.Locale = new System.Globalization.CultureInfo("zh-CN"); // // label4 // this.label4.Location = new System.Drawing.Point(96, 16); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(100, 16); this.label4.TabIndex = 0; this.label4.Text = "入住单号"; // // txt4 // this.txt4.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet21, "帐单明细.入住单号")); this.txt4.Location = new System.Drawing.Point(96, 32); this.txt4.Name = "txt4"; this.txt4.ReadOnly = true; this.txt4.Size = new System.Drawing.Size(176, 21); this.txt4.TabIndex = 1; this.txt4.Text = ""; // // txt5 // this.txt5.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet21, "帐单明细.消费金额")); this.txt5.Location = new System.Drawing.Point(96, 80); this.txt5.Name = "txt5"; this.txt5.ReadOnly = true; this.txt5.Size = new System.Drawing.Size(176, 21); this.txt5.TabIndex = 1; this.txt5.Text = ""; // // label5 // this.label5.Location = new System.Drawing.Point(96, 64); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(100, 16); this.label5.TabIndex = 0; this.label5.Text = "消费金额"; // // txt6 // this.txt6.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet21, "帐单明细.备注")); this.txt6.Location = new System.Drawing.Point(96, 128); this.txt6.Name = "txt6"; this.txt6.ReadOnly = true; this.txt6.Size = new System.Drawing.Size(464, 21); this.txt6.TabIndex = 1; this.txt6.Text = ""; // // label6 // this.label6.Location = new System.Drawing.Point(96, 112); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(100, 16); this.label6.TabIndex = 0; this.label6.Text = "备注"; // // label7 // this.label7.Location = new System.Drawing.Point(352, 16); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(100, 16); this.label7.TabIndex = 0; this.label7.Text = "消费时间"; // // label8 // this.label8.Location = new System.Drawing.Point(352, 64); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(100, 16); this.label8.TabIndex = 0; this.label8.Text = "消费内容"; // // cmb1 // this.cmb1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet21, "帐单明细.消费时间")); this.cmb1.Enabled = false; this.cmb1.Location = new System.Drawing.Point(352, 32); this.cmb1.Name = "cmb1"; this.cmb1.Size = new System.Drawing.Size(208, 20); this.cmb1.TabIndex = 2; this.cmb1.DropDown += new System.EventHandler(this.cmb1_DropDown); this.cmb1.Leave += new System.EventHandler(this.cmb1_Leave); // // cmb2 // this.cmb2.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet21, "帐单明细.消费内容")); this.cmb2.Enabled = false; this.cmb2.Items.AddRange(new object[] { "加收房费", "加收水电费", "视频点播费", "宽带上网费", "商品使用费", "其他费用"}); this.cmb2.Location = new System.Drawing.Point(352, 80); this.cmb2.Name = "cmb2"; this.cmb2.Size = new System.Drawing.Size(208, 20); this.cmb2.TabIndex = 2; // // btnSelect // this.btnSelect.Enabled = false; this.btnSelect.Image = ((System.Drawing.Image)(resources.GetObject("btnSelect.Image"))); this.btnSelect.Location = new System.Drawing.Point(280, 32); this.btnSelect.Name = "btnSelect"; this.btnSelect.Size = new System.Drawing.Size(24, 24); this.btnSelect.TabIndex = 73; this.btnSelect.Click += new System.EventHandler(this.btnSelect_Click); this.btnSelect.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnSelect_MouseUp); // // calen1 // this.calen1.Location = new System.Drawing.Point(432, 208); this.calen1.Name = "calen1"; this.calen1.TabIndex = 131; this.calen1.Visible = false; this.calen1.DateSelected += new System.Windows.Forms.DateRangeEventHandler(this.calen1_DateSelected); // // sqlSelectCommand1 // this.sqlSelectCommand1.CommandText = "SELECT 帐单编号, 入住单号, 消费内容, 消费金额, 消费时间, 备注 FROM 帐单明细 WHERE (入住单号 LIKE @Param3) AND (" + "消费内容 LIKE @Param4 OR 消费内容 IS NULL)"; this.sqlSelectCommand1.Connection = this.sqlConnection1; this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param3", System.Data.SqlDbType.VarChar, 36, "入住单号")); this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param4", System.Data.SqlDbType.VarChar, 40, "消费内容")); // // sqlInsertCommand1 // this.sqlInsertCommand1.CommandText = "INSERT INTO 帐单明细(入住单号, 消费内容, 消费金额, 消费时间, 备注) VALUES (@入住单号, @消费内容, @消费金额, @消费时间, " + "@备注); SELECT 帐单编号, 入住单号, 消费内容, 消费金额, 消费时间, 备注 FROM 帐单明细 WHERE (帐单编号 = @@IDENTITY" + ")"; this.sqlInsertCommand1.Connection = this.sqlConnection1; this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@入住单号", System.Data.SqlDbType.VarChar, 36, "入住单号")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@消费内容", System.Data.SqlDbType.VarChar, 40, "消费内容")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@消费金额", System.Data.SqlDbType.Money, 8, "消费金额")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@消费时间", System.Data.SqlDbType.DateTime, 4, "消费时间")); this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@备注", System.Data.SqlDbType.VarChar, 80, "备注")); // // sqlUpdateCommand1 // this.sqlUpdateCommand1.CommandText = @"UPDATE 帐单明细 SET 入住单号 = @入住单号, 消费内容 = @消费内容, 消费金额 = @消费金额, 消费时间 = @消费时间, 备注 = @备注 WHERE (帐单编号 = @Original_帐单编号) AND (入住单号 = @Original_入住单号) AND (备注 = @Original_备注 OR @Original_备注 IS NULL AND 备注 IS NULL) AND (消费内容 = @Original_消费内容 OR @Original_消费内容 IS NULL AND 消费内容 IS NULL) AND (消费时间 = @Original_消费时间 OR @Original_消费时间 IS NULL AND 消费时间 IS NULL) AND (消费金额 = @Original_消费金额 OR @Original_消费金额 IS NULL AND 消费金额 IS NULL); SELECT 帐单编号, 入住单号, 消费内容, 消费金额, 消费时间, 备注 FROM 帐单明细 WHERE (帐单编号 = @帐单编号)"; this.sqlUpdateCommand1.Connection = this.sqlConnection1; this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@入住单号", System.Data.SqlDbType.VarChar, 36, "入住单号")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@消费内容", System.Data.SqlDbType.VarChar, 40, "消费内容")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@消费金额", System.Data.SqlDbType.Money, 8, "消费金额")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@消费时间", System.Data.SqlDbType.DateTime, 4, "消费时间")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@备注", System.Data.SqlDbType.VarChar, 80, "备注")); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_帐单编号", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "帐单编号", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_入住单号", System.Data.SqlDbType.VarChar, 36, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "入住单号", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_备注", System.Data.SqlDbType.VarChar, 80, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "备注", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_消费内容", System.Data.SqlDbType.VarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "消费内容", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_消费时间", System.Data.SqlDbType.DateTime, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "消费时间", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_消费金额", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "消费金额", System.Data.DataRowVersion.Original, null)); this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@帐单编号", System.Data.SqlDbType.Int, 4, "帐单编号")); // // sqlDeleteCommand1 // this.sqlDeleteCommand1.CommandText = @"DELETE FROM 帐单明细 WHERE (帐单编号 = @Original_帐单编号) AND (入住单号 = @Original_入住单号) AND (备注 = @Original_备注 OR @Original_备注 IS NULL AND 备注 IS NULL) AND (消费内容 = @Original_消费内容 OR @Original_消费内容 IS NULL AND 消费内容 IS NULL) AND (消费时间 = @Original_消费时间 OR @Original_消费时间 IS NULL AND 消费时间 IS NULL) AND (消费金额 = @Original_消费金额 OR @Original_消费金额 IS NULL AND 消费金额 IS NULL)"; this.sqlDeleteCommand1.Connection = this.sqlConnection1; this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_帐单编号", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "帐单编号", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_入住单号", System.Data.SqlDbType.VarChar, 36, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "入住单号", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_备注", System.Data.SqlDbType.VarChar, 80, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "备注", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_消费内容", System.Data.SqlDbType.VarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "消费内容", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_消费时间", System.Data.SqlDbType.DateTime, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "消费时间", System.Data.DataRowVersion.Original, null)); this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_消费金额", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "消费金额", System.Data.DataRowVersion.Original, null)); // // ClientConsume // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(728, 502); this.Controls.Add(this.calen1); this.Name = "ClientConsume"; this.Text = "【消费记帐】"; this.Load += new System.EventHandler(this.ClientConsume_Load); this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.toolBar1, 0); this.Controls.SetChildIndex(this.dataGrid1, 0); this.Controls.SetChildIndex(this.groupBox2, 0); this.Controls.SetChildIndex(this.calen1, 0); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit(); this.groupBox2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataSet21)).EndInit(); this.ResumeLayout(false); } #endregion //-----显示和消费日期----- private void cmb1_DropDown(object sender, System.EventArgs e) { selectDate(cmb1); } //----------关闭日期控件的显示---------- private void cmb1_Leave(object sender, System.EventArgs e) { calen1.Visible=false; } //-----------单击下拉列表框下拉箭头时显示日期以供选择--------------- private void selectDate(ComboBox cb) { calen1.Left=cb.Left;//设置日期控件的位置 calen1.Top=cb.Top-calen1.Height-10+groupBox2.Top; if(cb.Text.Trim()!="") { calen1.SelectionStart=Convert.ToDateTime(cb.Text);//日历显示的时间为数据时间 calen1.SelectionEnd=Convert.ToDateTime(cb.Text); } calen1.Visible=true;//显示日期 calen1.Show(); } //-----------从日历控件中选择日期信息------------ private void calen1_DateSelected(object sender, System.Windows.Forms.DateRangeEventArgs e) { cmb1.Text=calen1.SelectionEnd.ToString(); } //-------------根据输入选择消费数据--------------- private void btnSearch_Click(object sender, System.EventArgs e) { da1.SelectCommand.Parameters[0].Value="%"; da1.SelectCommand.Parameters[1].Value="%"; if(txt1.Text.Trim()!="") { da1.SelectCommand.Parameters[0].Value="%"+txt1.Text.Trim()+"%"; } if(txt2.Text.Trim()!="") { da1.SelectCommand.Parameters[1].Value="%"+txt2.Text.Trim()+"%"; } dataSet21.Clear();//刷新数据集 da1.Fill(dataSet21); } private void ClientConsume_Load(object sender, System.EventArgs e) { da1.SelectCommand.Parameters[0].Value="%"; da1.SelectCommand.Parameters[1].Value="%"; da1.Fill(dataSet21);//填充帐单明细 base.dataSet11=this.dataSet21; this.cmOrders=(CurrencyManager) BindingContext[dataSet21,"帐单明细"]; } //----------重写设置控件只读属性函数---------- protected override void SetModifyMode(bool blnEdit) { base.SetModifyMode (blnEdit); txt5.ReadOnly=!blnEdit; txt6.ReadOnly=!blnEdit; cmb1.Enabled=blnEdit; cmb2.Enabled=blnEdit; btnSelect.Enabled=blnEdit; } //-------重写新增记录时设置默认值函数-------- protected override void SetDefaultValue() { base.SetDefaultValue(); } //-------重写检查非空字段函数-------- protected override bool CheckNotNull() { if(txt4.Text.Trim()=="")// 检查入住单号 { MessageBox.Show("入住单号号不能为空","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop); return(false); } if(txt5.Text.Trim()=="")//检查消费金额 { MessageBox.Show("请输入消费金额","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop); return(false); } return base.CheckNotNull (); } //----------从入住单中双击选择入住单号----------- private void btnSelect_Click(object sender, System.EventArgs e) { string sql="select * from 入住单"; SelectTable newfrm=new SelectTable(sql,2); newfrm.Text="双击选择入住单号"; newfrm.ShowDialog(); } private void btnSelect_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { if(RZid=="") return; txt4.Text=RZid; } } }

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧