我使用C#windows窗体,我有richtextbox,我想用红色标记一些文本,一些用绿色,一些用黑色.
怎么办?附图.

如果有人能告诉我我是否理解它,我真的很感激:
class X
{
A a1=new A(); // reference on the stack, object value on the heap
a1.VarA=5; // on the stack - value type
A a2=a1; // reference on the stack, object value on the heap
a2.VarA=10; // on the stack - value type
}
Run Code Online (Sandbox Code Playgroud)
此外a1,a2引用都在堆栈上,而它们的"对象"值在堆上.但是VarA变量,它仍然是纯粹的价值类型呢?
class A
{
int VarA;
}
Run Code Online (Sandbox Code Playgroud) 在下面的代码中,我正在检查对象引用的相等性.
string x = "Some Text";
string y = "Some Other Text";
string z = "Some Text";
Console.WriteLine(object.ReferenceEquals(x, y)); // False
Console.WriteLine(object.ReferenceEquals(x, z)); // True
Console.WriteLine(object.ReferenceEquals(y, z)); // False
y = "Some Text";
Console.WriteLine(object.ReferenceEquals(x, y)); // True
Console.WriteLine(object.ReferenceEquals(x, z)); // True
Console.WriteLine(object.ReferenceEquals(y, z)); // True
Run Code Online (Sandbox Code Playgroud)
这里:
x并z指同一个对象; 我可以说x是实习并z使用了taht版本.好吧,我不确定这个; 如果我错了,请纠正我.y通过赋予它与x相同的值来改变它的值.我以为它会在这里创建一个新对象; 但我错了,它使用相同的参考.我的问题是:
.net使用字符串实习生?我想要显示:
Name [Textbox]
Age: [Textbox]
BlahBlahCatfish: [Textbox]
Run Code Online (Sandbox Code Playgroud)
但是,如果我只是简单地将代码插入其中,它就会像上面排列的那样排成一行.
我想要的是它排成一行:
Name: [Textbox]
Age: [Textbox]
BlahBlahCatfish: [Textbox]
Run Code Online (Sandbox Code Playgroud)
通常我会使用表,但我试图摆脱这种习惯并使用可爱的CSS.没有数十亿的div和东西,如何做到这一点的想法?
我们有一个自定义控件,它具有System.Nullable类型的"Value"属性(又名System.DateTime?).我们有一个具有相同类型的"已接收"属性的对象.当我们尝试将控件绑定到对象时,抛出以下InvalidCastException:
从 '的System.DateTime' 无效转换到 'System.Nullable`1 [[System.DateTime的,mscorlib程序,版本= 2.0.0.0,文化=中性公钥= b77a5c561934e089]]'.
这是我们正在做的事情:
对象属性:
private System.DateTime? _dateTimeReceived;
public System.DateTime? DateTimeReceived
{
get
{
return this._dateTimeReceived;
}
set
{
this._dateTimeReceived = value;
this.OnChanged("DateTimeReceived", value); //Implements INotifyPropertyChanged and fires PropertyChanged event
}
}
Run Code Online (Sandbox Code Playgroud)
控制属性:
private System.DateTime? _value;
[System.ComponentModel.Category("Behavior")]
[System.ComponentModel.Description("The current date value for this control")]
public new System.DateTime? Value
{
get
{
return this._value;
}
set
{
this._value = value;
}
}
Run Code Online (Sandbox Code Playgroud)
在应用程序中,抛出异常的位置:
this.dateReceived.DataBindings.Add("Value", this._object, "DateTimeReceived");
Run Code Online (Sandbox Code Playgroud)
如您所见,对象的属性(this._object.DateTimeReceived)是System.DateTime?类型和控件的属性(this.dateReceived.Value)是一个System.DateTime?类型.
为什么会导致InvalidCastException?我们如何纠正这一点,使其正确绑定?
更新2009-10-29 14:26 CDT:
这是堆栈跟踪: …
我必须使用XNA在3d模型上创建一个二维菜单.现在,我已经创建了2D的spritebatch和一个3d模型.但是,正如我已经注意到的,并且在其他地方被提及,由于z缓冲区问题,模型没有正确显示.根据教程,我应该在draw方法中再次启用DepthBuffer.但是,不知何故,当我使用时:
GraphicsDevice.DepthStencilState.DepthBufferEnable = true;
Run Code Online (Sandbox Code Playgroud)
调试期间代码抛出错误,说,
无法更改只读DepthStencilState.状态对象在第一次绑定到GraphicsDevice时变为只读.要更改属性值,请创建一个新的DepthStencilState实例.
现在,我也试图创建一个新的DepthStencilState实例,但是,即使这样似乎也不起作用.我总是得到相同的错误,即使帮助文档建议它的读/写值.
请帮我弄清楚如何正确显示3D模型.
这是Draw代码供参考.
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] transforms = new Matrix[myModel.Bones.Count];
myModel.CopyAbsoluteBoneTransformsTo(transforms);
foreach (ModelMesh mesh in myModel.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
//effect.DirectionalLight0.Enabled = true;
//effect.DirectionalLight0.DiffuseColor = Color.AntiqueWhite.ToVector3();
//effect.DirectionalLight0.Direction = new Vector3(0, 0, 0);
effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(myModelRotation) * Matrix.CreateTranslation(myModelPosition);
effect.View = Matrix.CreateLookAt(new Vector3(0, 0, 3000), Vector3.Zero, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45f),
GraphicsDevice.Viewport.AspectRatio, 1, 5000);
}
mesh.Draw();
}
spriteBatch.Begin();
spriteBatch.Draw(myTexture, new Vector2(0, 0), Color.White);
spriteBatch.End();
DepthStencilState d …Run Code Online (Sandbox Code Playgroud) Enumerable.Range(0, int.MaxValue)
.Select(n => Math.Pow(n, 2))
.Where(squared => squared % 2 != 0)
.TakeWhile(squared => squared < 10000).Sum()
Run Code Online (Sandbox Code Playgroud)
此代码是否会迭代从0到最大范围的所有整数值,或者仅通过整数值来满足take-while,where和select运算符?有人可以澄清一下吗?
编辑:我第一次尝试确保它按预期工作是愚蠢的.我撤销它:)
我有一些代码:
string pathUser = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string pathDownload = Path.Combine(pathUser, @"documents\iracing\setups\");
DirectoryInfo dinfo = new DirectoryInfo(pathDownload); // Populates field with all Sub Folders
FileInfo[] Files = dinfo.GetFiles("*.sto");
foreach (FileInfo file in Files)
{
listBox2.Items.Add(file.Name);
}
Run Code Online (Sandbox Code Playgroud)
我希望documents\iracing\setups\显示以下子文件:而不是文件...包括.sto文件.我只需要列出子文件夹....我不知道该怎么做?谢谢!
这是我的问题:我们的产品有自动构建过程.在编译其中一个VB6项目期间,会弹出一个消息框,要求用户在继续之前单击"确定".作为一个自动化过程,这是一件坏事,因为它可能最终会在那里停留数小时而不会移动,直到有人点击确定.我们已经研究了VB6代码来尝试抑制消息框,但似乎没有人能够弄清楚现在如何.因此,作为临时修复程序,我正在处理将在后台运行的程序,当弹出消息框时,将其关闭.到目前为止,我能够检测到消息弹出的时间,但我似乎无法找到正确关闭它的功能.该程序是用C#编写的,我使用user32.dll中的FindWindow函数来获取指向窗口的指针.到目前为止,我已经尝试了closeWindow,endDialog和postMessage来尝试关闭它,但它们似乎都没有用.closeWindow只是最小化它,endDialog会出现一个错误的内存异常,而postMessage什么都不做.有没有人知道任何其他功能会处理这个,或任何其他方式去除这个消息?提前致谢.
这是我目前的代码:
class Program
{
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
static void Main(string[] args)
{
IntPtr window = FindWindow(null, "Location Browser Error");
while(window != IntPtr.Zero)
{
Console.WriteLine("Window found, closing...");
//use some function to close the window
window = IntPtr.Zero;
}
}
}
Run Code Online (Sandbox Code Playgroud) 因为我试图用平滑和渲染的每个组合绘制字符串,Graphics.DrawString()我认为文本渲染器会更好地绘制我的字符串,但我认为是错误的.
这是它应该是这样的:

这就是它的样子:

这是我的代码:
Graphics objGraphics2 = Graphics.FromImage(objBitmap);
objGraphics2.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
objGraphics2.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
objGraphics2.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
objGraphics2.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
Font textFont = new Font(textFontFamily, PxtoEm(textSize));
SolidBrush b = new SolidBrush(textColor);
TextRenderer.DrawText(objGraphics2, textValue, textFont, new Rectangle(0, 0, Width, Height), textColor);
Run Code Online (Sandbox Code Playgroud)
我的PxtoEm方法错了吗?
public float PxtoEm(int px)
{
float em = (float)(Convert.ToDouble(Convert.ToDouble(px) * Convert.ToDouble(72) / Convert.ToDouble(objBitmap.HorizontalResolution)));
return em;
}
Run Code Online (Sandbox Code Playgroud)
我需要一些建议,因为这非常糟糕,更大的字体和图像不会缩小,情况会变得更糟.
更新:使用更大的字体(即20px),但使用较小的字体,它会在某些字母上被删除:
这就是它与字体Arial 10px一起使用的方式:

这是结果 Graphics.DrawString()

你可以看到它真的不是很好,但我最接近.我对代码进行了一些更改,并使用更大的字体获得了更好的结果
这就是如何使用字体Arial 20px:

这是绘图结果:

这里是更改的代码(我直接使用em方法并使用像素,切换到Graphics.DrawString()而不是TextRenderer.DrawText()
Graphics objGraphics = Graphics.FromImage(objBitmap);
objGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
objGraphics.TextRenderingHint …Run Code Online (Sandbox Code Playgroud)