Tag: winforms

使用c#在windows窗体中级联comboBox

我试图在Windows窗体应用程序中从同一个表更改的combobox1 selectedText上填充Combobox2。 我正在使用sql serevr 2008数据库。 我无法在combobox上填充combobox2所选文本已更改。 这是我尝试过的: private void Purchase_Load(object sender, EventArgs e) { fillName(); comboBoxName.SelectedIndex = -1; } private void comboBoxName_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxName.SelectedText != “”) { fillMake(); } } private void fillName() { SqlConnection con = new SqlConnection(@”Data Source=ashish-pc\;Initial Catalog=HMS;Integrated Security=True”); con.Open(); string str = “Select Item_Name from Item”; SqlCommand […]

RichTextBox和UserPaint

我正在尝试绘制RichTextBox,但我能做到的唯一方法是调用OnPaint/OnPaintBackground 。 问题是除非“UserPaint”标志打开,否则不会调用OnPaint或OnPaintBackground,但是当此标志打开时 – 文本本身不会被绘制! 我该怎么解决这个问题?

在BackgroundWorker中调用ShowDialog

我有一个WinForms应用程序,我的后台工作人员在其中执行同步任务,添加新文件,删除旧文件等。 在我的后台工作者代码中,我想向用户显示一个自定义表单,告诉他将删除什么以及如果他继续将添加什么,使用YES / NO按钮获取他的反馈。 我想知道在后台工作者的doWork方法中做这样的事情是否可行? 如果没有,我该怎么办? 请指教.. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { MyForm f = new MyForm(); f.FilesToAddDelete(..); DialogResult result = f.ShowDialog(); if(No…) return; else //keep working… }

从另一种forms调用变量c#

我在Form1有一个DataGridView ,我正在使用此代码显示另一个名为Generator表单: private void button1_Click(object sender, EventArgs e) { Form gen = new Generator(); // Form gen = new Generator(Form this); //* I tried this but is not working *// gen.Show(); } 在Generator表单中,我需要读取或修改Form1 datagridview中的内容。 public partial class Generator : Form { public Form myForm; public Generator() { InitializeComponent(); } public Generator(Form frm) { myForm = […]

如何在Windows窗体中保存在运行时创建的控件

这是我的代码 private void make_Book(int x, int y, string name) { #region Creating Book // this code is initializing the book(button) Button book1 = new Button(); Image img = button1.Image; book1.Image = img; book1.Name = name; book1.Height = img.Height; book1.Width = img.Width; book1.Location = new Point(44 + x, 19 + y); book1.Click += new EventHandler(myClickHandler); groupBox1.Controls.Add(book1); […]

使用C#.net在winform中调用和使用Web API

我是初学者并创建winform应用程序。 其中我必须使用API​​进行简单的CRUD操作。 我的客户与我共享了API,并要求以JSON的forms发送数据。 API: http : //blabla.com/blabla/api/login-valida KEY:“HelloWorld” 价值:{“email”:“user@gmail.com”,“密码”:“123456”,“时间”:“2015-09-22 10:15:20”} 响应:Login_id 如何将数据转换为JSON,使用POST方法调用API并获得响应? 编辑 stackoverflow上的某个地方我找到了这个解决方案 public static void POST(string url, string jsonContent) { url=”blabla.com/api/blala” + url; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(baseURL); request.Method = “POST”; System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); Byte[] byteArray = encoding.GetBytes(jsonContent); request.ContentLength = byteArray.Length; request.ContentType = @”application/json”; using (Stream dataStream = request.GetRequestStream()) { dataStream.Write(byteArray, 0, […]

WinForms:响应正在应用的BindingSource

是否有一个事件可以锁定,以便在数据源应用于其绑定控件时得到通知? 还是有另一个事件,我保证数据源已被应用? 我正在使用WinForms(来自WPF)并使用带有数据绑定值的标签,以确定我正在使用的控件类型。 许多控件可以具有相同的标记值,并且我必须使用所需的标记检索控件以执行业务逻辑。 问题是我不知道何时执行搜索标记值。 我在调用后尝试立即搜索标记值: myBindingSource.DataSource = OutputFunctions.Instance; //Yes… I’m binding to a singleton with a list of properties. //Its not the best method, but works. 在我的Form.Load事件处理程序中。 但是,在搜索过程中,我看到标签值未设置。 如果我只是设置数据源,那该怎么办? 从我的表单的内部托管代码隐藏可以看出,我已通过设计器的Property窗口正确设置了值: this.textBoxDTemp.DataBindings.Add(new System.Windows.Forms.Binding( “Tag”, this.myBindingSource, “KNOB_DRIVER_TEMP”, true)); 我已经看过BindingComplete ,老实说看起来非常有前途,除了它在绑定初始化期间没有触发,即使该值应该从数据源传播到目标控件。 编辑:根据要求,数据源首先在表单的内部代码隐藏中设置如下: this.myBindingSource.DataSource = typeof(OutputFunctions); 如果它有帮助,这里是单身人士。 public class OutputFunctions { private static OutputFunctions instance; public static OutputFunctions […]

全屏Windows窗体超出了屏幕尺寸

我有一个WinForms应用程序(.NET 4),需要全屏显示或无边框最大化。 在Form_Shown事件中使用以下代码: #if (DEBUG) var debug = true; #else var debug = false; #endif this.Text = “”; this.ControlBox = false; this.ShowInTaskbar = true; //this.TopMost = debug; this.TopLevel = true; this.FormBorderStyle = FormBorderStyle.None; if (debug) { this.Bounds = Screen.FromControl(this).WorkingArea; } else { this.WindowState = FormWindowState.Maximized; } 如果仔细观察下面的屏幕截图,顶部和底部区域会被几个像素截断。 此外,如果最大化,窗口仍然不会覆盖任务栏。 请注意,我只连接了一台显示器。 没有辅助显示。 如何处理上述两个问题的任何建议将不胜感激。 更新:上面的代码似乎适用于没有MenuStrip或StatusStrip表单。

如何更改CheckedListBox项目的垂直空间

我需要更改CheckedListBox项的垂直空间,以便它们适合另一侧的文本框: CheckedListBox和“TextBox”并排http://sofzh.miximages.com/c%23/358vt52.png如何做到这一点? 经过一些研究后我发现CheckedListBoxinheritance了ListBox ,所以它必须有它的公共属性ItemHeight ,但由于某种原因它不会 我试过这个: ListBox l = CheckedList as ListBox; l.ItemHeight = 30; 但它不起作用

PrintPage PrintPageEventHandler打印太多副本

我必须为我们公司生产的产品打印运输标签。 为了让我自己了解这些标签的结果,我使用Windows窗体进行设计。 这允许我使用Label控件定位我的文本,设置正确的字体等,添加自定义BarCode控件,并使用Panel控件“ 花哨 ”将项目分组到框中。 每页包含两(2)个标签。 当我的代码打印标签文档时,我要求2,4或6份副本。 有时,也会使用“打印预览”。 在这种情况下,我必须重置创建的标签数量。 但是,当文件打印时: 如果请求是2份,代码打印2张纸(4个标签) 如果请求是4份,代码打印8张纸(16个标签) 如果请求是6份,代码打印高达18页(36个标签) 有没有人看到一种模式? 我不。 这是我的打印命令: public int Print(string docName, int rows, int columns, int copies) { short shortCopies = (short)copies; LabelsHorizontal = rows; LabelsVertical = columns; Size docSize = PrintPreview.Document.DefaultPageSettings.Bounds.Size; float height = 0.8F * Screen.PrimaryScreen.WorkingArea.Size.Height; float width = (height * docSize.Width) / docSize.Height; […]