我应该使用Windows Forms Application在2D中创建一个魔术方块.它应该如下所示:
但是,用户应该能够决定正方形的大小(3x3,5x5,7x7等).我已经在控制台应用程序中编写了代码,但我不知道如何添加2D图形.
有人已经问过这个问题(如何将我的结果放入GUI?),其中一个答案是使用DataGridView,但我不确定这是否是我正在寻找的,因为我无法让它看起来喜欢这张照片.
任何想法或建议?
当我在第一个表单上的dataGridView中选择行以在另一个表单上用该值填充comboBox时,我想设置comboBox.SelectedValue,
在我的加载事件我有第二种形式comboBox.DataSource,DisplayMember,ValueMember正确设置它,但是当我设置了selectedValue在第一什么也没有发生.当我在一个表格上做的时候,一切都很好
我正在将一个项目从 a 粘贴TreeView到 a TextBox,但我想将该项目粘贴到鼠标的当前位置,并显示一个插入符号,如下图所示。带插入符号的图像:

这是我的代码:
private void tvOperador_ItemDrag(object sender, ItemDragEventArgs e)
{
var node = (TreeNode)e.Item;
if (node.Level > 0)
{
DoDragDrop(node.Text, DragDropEffects.Copy);
}
}
private void txtExpresion_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(string))) e.Effect = DragDropEffects.Copy;
}
private void txtExpresion_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(System.String)))
{
string Item = (System.String)e.Data.GetData(typeof(System.String));
string[] split = Item.Split(':');
txtExpresion.Text += split[1];
}
}
Run Code Online (Sandbox Code Playgroud) 我实现了一种调用函数ProcessJob的作业调度.现在在这个方法里面我需要为我的一个页面生成url,即DoanloadPage.aspx?some_params.该网址通过电子邮件发送给用户,当用户点击该链接时,它将转到该页面.
这里的问题是我没有在Web请求方法中生成url,或者我没有访问Request对象的权限.需要在自定义类中生成URL,该类是线程化的,即不在Web请求中.
所以我不能使用这些解决方案:
HostingEnvironment.MapPath("test.aspx");
VirtualPathUtility.ToAbsolute("123.aspx");
HttpContext.Current.Request.Url.Authority;
Run Code Online (Sandbox Code Playgroud)
这些都不起作用,因为我认为它们都以某种方式依赖于当前的请求或会话.那么我如何在我的代码中为我的应用程序生成网址,以便我可以随意使用它们.
有什么可能的方法来更改日历控件的宽度和高度。我想更改日历的宽度和高度。当我在Google上找到Google时,执行以下步骤:1)在面板中放置月份日历,并允许添加true。并增加面板尺寸。对我不起作用。2)将月历日历放到组框中并停靠。这个月会显示很多个月。3)增加日历控件的字体大小,对我不起作用。
有什么办法可以做到这一点。预先感谢您的评论
我写了一个方法来获取属性值属性:
public string GetAttributeValueByNameAttributeAndProperty(CodeClass cc, string nameAttribute, string nameProperty)
{
var value = "";
foreach(CodeAttribute ca in cc.Attributes)
{
if(ca.Name.Contains(nameAttribute) && ca.Value.Contains(nameProperty))
{
value = ca.Value.Remove(0,ca.Value.IndexOf(nameProperty));
value = value.Replace(" ","");
if(value.Contains(","))
value = value.Remove(ca.Value.IndexOf(","));
}
}
return value;
}
Run Code Online (Sandbox Code Playgroud)
例如:
我有属性 [Map(Name = "MenuItem, Availability" )]
我调用GetAttributeValueByNameAttributeAndProperty(codeclass,"Map","Name")之后,该方法获取CodeAttribute.Value并返回字符串:Name ="MenuItem,Availability"删除"Name ="和额外字符后,按","拆分
但我的高级程序员告诉我,这种方法不灵活,我需要找到一种更方便的方法来获取CodeAttribute.Value中的内部数据.
你有什么想法/例子吗?
我想在每行的末尾有一个删除按钮,DataGridView然后单击我要从绑定列表中删除所需的行,该列是我的网格的数据源.
但我似乎无法做到这一点我在产品类中创建了一个按钮对象,并使用唯一的id实例化它以从列表中删除该对象.但是按钮没有显示在行中.
表单中有TextBox,用户可以输入文本,当他们按下Add按钮时,产品的新对象将使用提供的字段进行实例化,然后将其添加到BindingList.
最后,这个列表被绑定到,DataGridView并且细节显示在网格中.(我已经完成了这一部分).
最后,通过单击"保存"按钮,列表将保存在数据库中.
public class Product{
public string Brand { get; set; }
public int ProductPrice { get; set; }
public int Quantity { get; set; }
public product(string brand,int productPrice, int quantity){
this.Brand = brand;
this.ProductPrice = productPrice;
this.Quantity = quantity;
}
}
public partial class MainForm: Form{
.....
BindingList<Product> lProd = new BindingList<Product>();
private void btnAddProduct_Click(object sender, EventArgs e){
string Brand = txtProBrand.Text;
int Price = Convert.ToInt32(txtPrice.Text);
int Quantity = …Run Code Online (Sandbox Code Playgroud) 我对async/await编程很新,有时我觉得我理解它,然后突然发生了一些事情,并引发了我的循环.
我在测试winforms应用程序中尝试这个,这是我的一个版本的片段.这样做会阻止UI
private async void button1_Click(object sender, EventArgs e)
{
int d = await DoStuffAsync(c);
Console.WriteLine(d);
}
private async Task<int> DoStuffAsync(CancellationTokenSource c)
{
int ret = 0;
// I wanted to simulator a long running process this way
// instead of doing Task.Delay
for (int i = 0; i < 500000000; i++)
{
ret += i;
if (i % 100000 == 0)
Console.WriteLine(i);
if (c.IsCancellationRequested)
{
return ret;
}
}
return ret;
}
Run Code Online (Sandbox Code Playgroud)
现在,当我通过在Task.Run中包装"DoStuffAsync()"的主体进行轻微更改时,它的工作完全正常
private async Task<int> DoStuffAsync(CancellationTokenSource c)
{ …Run Code Online (Sandbox Code Playgroud) 我在按钮动作中有一个循环用于删除我的空项目ListView,但问题是,当我按下按钮时,它只删除了单个项目.我的意思是:当一个接一个的时候,它不会删除项目:
例:
a1 = ""
a2 = "qwe"
a3 = ""
a4 = ""
a5 = "qwe"
Run Code Online (Sandbox Code Playgroud)
所以,点击按钮后,结果将是:
a2 = "qwe"
a3(or a4 idk) = ""
a5 = "qwe"
Run Code Online (Sandbox Code Playgroud)
我认为这很容易出现逻辑问题,但我无法弄明白.
for (int i = 0; i < listView1.Items.Count; i++)
{
if (listView1.Items[i].SubItems[2].Text == "")
{
listView1.Items[i].Remove();
}
}
Run Code Online (Sandbox Code Playgroud)
所以问题是循环在找到空值后跳过一次检查.我如何解决它?
我PropertyGrid在我的项目中使用 Winform ,一切正常,但选项卡顺序。
我想在点击时切换到下一个属性,Tab但事实上,选择从属性网格移到下一个控件。我不知道如何完成这项工作?
谢谢
c# ×10
.net ×8
winforms ×8
2d ×1
asp.net ×1
async-await ×1
asynchronous ×1
bindinglist ×1
datagridview ×1
listview ×1
propertygrid ×1
t4 ×1
textbox ×1
treeview ×1
webforms ×1