我在多线程中使用toolStripStatusLabel,尽管它是另一个与toolStripStatusLabel交互的线程,但我的statusStrip的invokeRequired方法总是返回false (我还强制创建句柄)。在这个线程中,我可以访问toolStripStatusLabel (from else子句),更新它,但我所做的编辑不能显示在主UI中。下面是我的代码:
public void safeThreaded()
{
Form2 form = new Form2();
StatusStrip ss = (StatusStrip
在toolstripstatuslabel中,我正在添加图像并显示它,如下所示。
情况1:设置图像列表大小不起作用
案例2:设置label.Not的工作大小
在上述两种情况下,大小都没有得到反映。
StatusStrip statusStrip = new StatusStrip();
//Set the size of the status bar
statusStrip.AutoSize = false;
ImageList imgList = new ImageList();
...Add resource images to image list
imgList.ImageSi
我正在编写一个从System.ComponentModel.BackgroundWorker类派生的类。我之所以在我的项目中这样做,是因为我需要在不同类型的状态更新事件中返回大量信息,这取决于引发的事件。当试图从任何更新事件更新任何控件(主窗体)时,我将收到以下错误:
System.InvalidOperationException:“跨线程操作无效:控件”从创建线程的线程以外的线程中访问。
我试图更新的第一个控件是ToolStripStatusLabel,它没有.Invoke()方法。我在下面创建了一个最少可验证的例子。要重新创建错误,只需创建一个针对Windows Forms Ap
在这种方法中,我想要生成报告:
private int reportingmethod()
{
if (result.Contains("forumPage"))
{
toolStripStatusLabel1
int index2 = result.IndexOf("\" text");
result = result.Remove(
我需要能够在C# Windows Forms应用程序中的ToolStripStatusLabel项上设置图标。该项目将显示图像和文本。我以为我可以在这样的项目上使用图标,但我错了。从现有图标对象创建Image对象的最佳方式是什么?
预期的代码将类似于:
Image image = new Image(); // Get this image somehow from a pre-existing Icon object
serverInfoToolStripStatusLabel.Text = "Connected to server X";
serverInfoToolStr
我有一个标签和这个代码:
string User = Environment.UserName;
toolStripStatusLabel1.Text = "This Software is Licensed to:" + User;
出于某种原因,输出是:
This Software is Licensed to:UserName
在我的应用程序中,我有一个负责所有数据库操作的类。它从主类调用,并在操作完成后使用委托来调用方法。因为它是异步的,所以我必须在GUI上使用invoke,所以我创建了一个简单的扩展方法:
public static void InvokeIfRequired<T>(this T c, Action<T> action)
where T: Control
{
if (c.InvokeRequired)
{
c.Invoke(new Action(() =
请告诉我,在启用StatusStrip时,如何显示CAPS_LOCK键。我试着遵循下面的例子:和,但是我的应用程序中没有显示任何东西。我创建了一个新项目,添加了StripStatusLabel元素,并试图向其提供任何信息。奇怪的是,只有在初始化方法中才能获得显示:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
toolStripStatusLabel1.Text = "111";
}
}
但在另一种方法中,它不起作用。