我正在关注winforms的这个教程,到目前为止,教程正在编写表单而不使用工具箱.我相信它很快就会更深入地介绍工具箱.
在本教程之后,我在以下两段代码中进行了部分类:
第一档:
using System;
using System.Windows.Forms;
public class Numeric : System.Windows.Forms.TextBox
{
public Numeric()
{
}
}
public partial class Exercise
{
private Numeric txtbox;
System.ComponentModel.Container components;
}
Run Code Online (Sandbox Code Playgroud)
第二档:
using System;
using System.Windows.Forms;
public partial class Exercise : Form
{
private void InitializeComponent()
{
txtbox = new Numeric();
Controls.Add(txtbox);
}
public Exercise()
{
InitializeComponent();
}
}
public class program
{
public static int Main()
{
Application.Run(new Exercise());
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
当我用F5运行代码时,一切看起来都很好:表单弹出文本框.
但出于某种原因,当我右键单击第二个文件并选择"视图设计器"时,我收到一条错误,上面写着"变量'txtbox'未声明或未被分配".我可以选择"忽略并继续",这会将我引导到一个没有文本框的表单.
为什么会这样?我知道有些人认为我应该使用工具箱,这可能是最明智的做法,但我仍然想知道为什么会这样.
我已经找到了关于如何在asp.net中使用Razor Engine用于电子邮件模板的链接,并且它运行良好.但我试图在电子邮件模板中添加带有图像的徽标.
像这样的东西:
EmailTemplate.cshtml (顺便说一下这是一个强类型的视图)
<html>
<body>
<img src="logo.jpg" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我尝试在电子邮件中提交它时,似乎没有读取图像路径,它只在内容中呈现X.
我正在考虑将图像路径作为模型的一部分传递,但这似乎很奇怪.有没有办法实现这个目标?
任何帮助将非常感激.谢谢
我正在管理各种联系信息 - 电话,地址,电子邮件,IM,其他我希望它看起来很好并节省空间,所以我想在WebBrowser控件中显示它.我可以动态地将标记和内容创建到流中,并以任何格式显示它,颜色和字体大小可以轻松调整.我还可以<input>添加添加,编辑和删除按钮.我喜欢这种方法,因为它似乎比RichTextBox更容易和更好看(如果你不这么认为,请纠正我.)
问题是关于响应这些按钮.如果选择了一个,我想隐藏WebBrowser并取消隐藏Panel,其中包含允许输入新联系人或编辑现有联系人所需的TextBox控件.我听说这可以做到.我希望得到一些建议.所有我能想到的是一些代码来获取一个AJAX调用,这会引发一个Windows事件,但这看起来很奇怪.
任何想法,链接或建议都会受到赞赏..甚至是一个很好的理由,为什么不这样做,但它似乎是高质量的信息呈现的好主意,我已经动态生成了大量的HTML.
我正在尝试DataGridView在winforms应用程序中显示来自相关实体的多个属性.这对我来说似乎很平常,但我很难找到例子.这是订单输入操作.OrderSheet数据,订单的ID和取件日期,然后是网格中的行项目(下面的模型中的OrderSheetItems).订单lineitems具有基于ProductId的导航属性Product.我可以将DataGridViewComboBoxColumn与ProductId一起用作ValueMember,将另一个字段用作DisplayMember.但我想在其他列,大小,颜色,材料等中包含更多数据.
这是加载数据的代码
try
{
_context.OrderSheets.Include(o => o.OrderSheetItems.Select(i => i.Product)).Load();
orderSheetBindingSource.DataSource = _context.OrderSheets.Local.ToBindingList();
}
catch (Exception ex)...
Run Code Online (Sandbox Code Playgroud)
ProductId位于一个单独的列中,仅用于实验,稍后将是组合框.那么有没有办法将其他列绑定到OrderSheetItem的Product导航属性中的数据,或者我是否必须在产品ID上处理CellValueChanged以在其他列中物理设置数据?如果有一种方法来绑定列,那么是通过OnLoad中的代码还是网格视图列设计器中的某个位置?
TIA,迈克
简短的介绍:
我有一个带有DataGridView的UserControl。我想向设计者公开DataGridView Columns集合,因此我可以在设计时更改用户控件上的列。
问:为此,我需要哪些设计师属性?
对于那些对较长版本感兴趣的人:
我有一个具有以下功能的UserControl:
该用户控件可以自主运行。它具有父控件要使用的一个功能:
UserControl引发两个事件:
我必须以几种形式显示此用户控件。唯一的区别是每个表格的DataGridViewColumn集合不同。
我可以以编程方式添加列,但是使用设计器创建列会更容易。
c# user-controls datagridview windows-forms-designer winforms
实际上,点击每个圆圈之后我想要改变它的颜色,例如,我希望它变成红色,总的来说,我想把它当作对照.
我知道如何在双击图片框时绘制代表图表节点的圆圈.我正在使用以下代码:
public Form1()
{
InitializeComponent();
pictureBox1.Paint += new PaintEventHandler(pic_Paint);
}
public Point positionCursor { get; set; }
private List<Point> points = new List<Point>();
public int circleNumber { get; set; }
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
positionCursor = this.PointToClient(new Point(Cursor.Position.X - 25, Cursor.Position.Y - 25));
points.Add(positionCursor);
Label lbl = new Label();
lbl.BackColor = Color.Transparent;
lbl.Font = new Font("Arial", 7);
lbl.Size = new Size(20, 15);
if (circleNumber >= 10)
{
lbl.Location = new Point(points[circleNumber].X + 3, points[circleNumber].Y + 6); …Run Code Online (Sandbox Code Playgroud) 我正在将一个项目从 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) 我正在实现一个web api,它将使用实体框架6获取数据.我正在使用Sql Server 2014和visual studio 2015.While调试CustomerDao类中的代码我在customerOrderContext对象中看到一个异常,虽然我可以看到记录在客户对象中.然而,在使用块执行后,我无法看到任何记录.
((System.Data.SqlClient.SqlConnection)customerOrderContext.Database.Connection).ServerVersion
CustomerDao
using (var customerOrderContext = new Entities())
{
return (from customer in customerOrderContext.Customers
select new CustomerOrder.BusinessObjects.Customers
{
Id = customer.Id,
FirstName = customer.FirstName,
LastName = customer.LastName,
Address = customer.Address,
City = customer.City,
Email = customer.Email,
Gender = customer.Gender,
State = customer.State,
Zip = customer.Zip
}).ToList();
}
Run Code Online (Sandbox Code Playgroud)
配置文件中的连接字符串如下所示
<add name="Entities" connectionString="metadata=res://*/EF.CustomerOrderContext.csdl|res://*/EF.CustomerOrderContext.ssdl|res://*/EF.CustomerOrderContext.msl;provider=System.Data.SqlClient;provider connection string="data source=Tom-PC\MSSQLSERVER2014;initial catalog=Ransang;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Run Code Online (Sandbox Code Playgroud)
上下文类如下
public partial class Entities : DbContext
{
public Entities()
: base("name=Entities")
{
}
protected override …Run Code Online (Sandbox Code Playgroud) 我写了用户控制(是的!)。但我希望它表现得像一个容器。可是等等!我知道
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design",
typeof(IDesigner))]
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)
这些都不起作用,因为我认为它们都以某种方式依赖于当前的请求或会话.那么我如何在我的代码中为我的应用程序生成网址,以便我可以随意使用它们.
c# ×10
.net ×8
winforms ×7
asp.net ×2
datagridview ×2
asp.net-mvc ×1
gdi+ ×1
picturebox ×1
razor ×1
textbox ×1
treeview ×1
webforms ×1