大约3个小时,我正在尝试解决此问题。我的组合框向我显示对象名称而不是一个值,例如:A

这是我的课:
namespace Supermarket
{
public class WhareHouseTable
{
public string name { get; set; }
public double cost { get; set; }
public string offer { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
private void Form1_Load(object sender, EventArgs e)
{
List<WhareHouseTable> product = new List<WhareHouseTable>();
product.Add(new WhareHouseTable { name = "A", cost = 0.63, offer = "Buy 2 for the price of 1" });
product.Add(new WhareHouseTable { name = "B", cost = 0.20 });
product.Add(new WhareHouseTable { name = "C", …Run Code Online (Sandbox Code Playgroud) 我正在尝试从本地资源文件向图表对象添加背景图像。显然,WinForms是愚蠢的,它不是让我使用图像,而是要在该文件的位置使用字符串。下面是一段代码,告诉我“无法将类型'System.Drawing.Bitmap'隐式转换为'字符串'”。...有什么想法吗?
private void myForm_Load(object sender, EventArgs e)
{
myChart.BackImage = myProject.Properties.Resources.myBackgroundImage;
}
Run Code Online (Sandbox Code Playgroud) 我有一个带有列表作为数据源的组合框。此列表包含具有其属性(名称,地址等)的对象(客户)。当我选择组合框的一个项目时,我想将信息(地址,邮政编码...)传递给表单上的某些文本框。在我的测试1tier应用程序中,这是正确的。但是我正在开发的主要应用程序是基于MVP的(我对此有自己的看法)。我面临的问题是铸造。由于我的看法不了解我的模型,因此不应允许我使用(客户)。string address = ((Customers)comboBox1.SelectedItem).CustomerAddress;
1层测试代码:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//getCustomers((int)comboBox1.SelectedValue);
//txtAddress.Text =Convert.ToString( comboBox1.SelectedValue);
Customers p = (Customers)comboBox1.SelectedItem;
string s = comboBox1.SelectedItem.ToString();
string address = ((Customers)comboBox1.SelectedItem).CustomerAddress;
txtAddress1.Text = address;
}
private void Form3_Load(object sender, EventArgs e)
{
using (var emp = new EmployerEFEntities())
{
var query = from customers in emp.Customers
select customers;
comboBox1.DisplayMember = "CustomerName";
comboBox1.ValueMember = "CustomerID";
comboBox1.DataSource = query.ToList();
}
}
Run Code Online (Sandbox Code Playgroud)
我已经研究了几天,但没有成功。我希望有人能给我正确的方向。
实际应用程序的代码:
视图:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
txtName.Text = comboBox1.SelectedValue.ToString(); …Run Code Online (Sandbox Code Playgroud) 在Winform C#应用程序上,我在表单上显示一个文本框.此文本框将显示一行,只有一行.我想展示并使用水平滚动条.
我将属性"scrollbar"设置为水平:ScrollBar不显示.我将WordWrap添加为false:ScrollBar不显示.我将MultiLine添加到true(即使一个ligne):ScrollBar不显示.
我显示的行比"contrôle"更"长",所以我真的需要一个滚动条:(
这是定义:
this.TxtBox_ApercuFichier.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.TxtBox_ApercuFichier.Location = new System.Drawing.Point(11, 30);
this.TxtBox_ApercuFichier.Multiline = true;
this.TxtBox_ApercuFichier.Name = "TxtBox_ApercuFichier";
this.TxtBox_ApercuFichier.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
this.TxtBox_ApercuFichier.Size = new System.Drawing.Size(702, 21);
this.TxtBox_ApercuFichier.TabIndex = 12;
Run Code Online (Sandbox Code Playgroud)
即使wordwrap为false,也是相同的结果.(我的文本框位于组框中).
有什么好主意吗?
非常感谢 :)
问候,
我想做一个MessageBox确认.这是消息框:
DialogResult dialog = MessageBox.Show("Etes vous sûre de vouloir fermer le programme ?", "Exit",MessageBoxButtons.YesNo);
if (dialog == DialogResult.Yes)
{
Application.Exit();
}
else if (dialog == DialogResult.No)
{
e.Cancel = true;
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我单击YES按钮时,弹出窗口不会自动关闭.我再次点击2次后将关闭.它应该从第一次关闭.
这似乎很容易,但我不确定我的错误在哪里;
我有一个简单的WinForms应用程序,但它有一些嵌入式资源(在"资源"下的子文件夹中),我想将其复制到计算机上的文件夹中.目前,我有后者工作(使用显式方法命名嵌入式资源以及应该去哪里):
string path = @"C:\Users\derek.antrican\";
using (Stream input = Assembly.GetExecutingAssembly().GetManifestResourceStream("WINFORMSAPP.Resources.SUBFOLDER.FILE.txt"))
using (Stream output = File.Create(path + "FILE.txt"))
{
input.CopyTo(output);
}
Run Code Online (Sandbox Code Playgroud)
但我仍在试图找出如何使前者工作:循环遍历"WINFORMSAPP.Resources.SUBFOLDER"文件夹中的所有资源并移动它们.我已经完成了很多谷歌搜索,但我仍然不确定如何在这个子文件夹中获取每个嵌入式资源的列表.
任何帮助将不胜感激!
请我是C#的新手,我创建了一个textBox和一个标签.我期待的是,如果我在textBox中键入一个值,我希望它显示在标签上,如果我更改了值,它也应该立即在标签上更改.它使用下面的代码,然后按回车键
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
label1.Text = textBox1.Text;
}
}
Run Code Online (Sandbox Code Playgroud)
但是我想要它而不按键盘上的Enter/Return键.
感谢您的理解
我观察到,根据控件的类型,VS有时会正确识别它所属的类型,但有时候它只会坚持一些EventArgs.
这是一些Winforms/.Net工件吗?
例如,在这种情况下,我在表单上有一些选项卡(f1).x将被正确识别为TabControlEventArgs,我可以插入其中.
f1.tabControl1.Selected
|> Event.filter (fun x -> x.TabPage.Name <> "Tab3")
|> Event.add (fun _ -> f1.comboBox2.Enabled <- false)
Run Code Online (Sandbox Code Playgroud)
但在下面的例子中,x只会显示EventArgs,我必须明确标识属性:
f1.my2CheckBox.CheckedChanged
|> Event.filter (fun x -> not f1.my2CheckBox.Checked)
|> Event.add (fun x -> f1.comboBox2.Enabled <- false)
Run Code Online (Sandbox Code Playgroud)
我认为这是因为某些控件传递的事件信息比其他控件更多.是否存在特定原因,或者这只是一个实现细节,基于某些控件可以执行的操作,因此例如对于tabcontrol,访问其页面是有意义的.
我有一个TreeView控件,其中包含多个元素,节点。有没有一种方法可以根据某些条件更改所选项目的前景色或背景色(默认情况下,将带有白色前景色的蓝色背景应用于所选元素)。就我而言,我将检索一个对象并检查其“ NeedSync”属性。如果值为true,则希望该元素具有绿色背景。如果为假,我希望背景为红色。
我查看了其他类似的线程,但要求使用树视图的_DrawItem方法更改未选择的元素的颜色。在WPF中,应该可以通过更改控件样式和指定触发器来实现。
那么在Windows窗体中呢?
编辑:我只需要更改所选元素的字体颜色或背景色,其他所有内容都应保持不变。有没有一种方法可以获取所选节点的默认样式源代码?实现drawNode方法会删除可折叠图标,边距和其他一些东西。
.NET框架包含定义所谓的"系统颜色"的类.对于WinForms,它是System.Drawing.SystemColors,对于WP*,它是System.Windows.SystemColors.我有两个问题:
SystemColors?如果颜色确实是可变的,我想保持我的应用程序的相同外观,无论用户配置的颜色和操作系统版本我假设我不能使用SystemColors而是创建我自己的颜色配置并在整个代码中使用它,是吗?