小编stu*_*rtd的帖子

使用包含大量数据的文本框还原WinForm

我在C#(VS2010)中创建了一个包含(以及其他)文本框控件的表单.文本框可能在某些时候包含大量数据(约300万个字符).

当滚动或移动的周围没有遇到任何问题的形式,但是当窗体最小化并恢复回来,重绘序列(我相信)被触发引起的大约5-10秒的大滞后的重新绘制表格.

我已经尝试了几种解决方案:

  1. 使用双缓冲区 - 根据我所读到的,双缓冲仅适用于表单本身而不适用于其控件

    this.SetStyle(ControlStyles.DoubleBuffer, true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.UserPaint, true);

  2. 禁用文本框redrew一次最小化使用:SendMessage(this.my_textBox.Handle, WM_SETREDRAW, false, 0); 并在表单恢复后启用.我注意到如果我不重新启用文本框重绘,表单重绘延迟也存在.

  3. 使用位图的手动双缓冲区 - 与#1类似的结果.

我在某处读到这个问题可能与文本框控件试图缩小或调整到数据量有关,但无法覆盖它.

我以前在MFC中有相同的项目,但没有遇到任何重复或滞后的问题.

请告诉我如何解决这个问题.

c# textbox restore repaint winforms

10
推荐指数
1
解决办法
366
查看次数

C#WinForms DataGridView背景颜色渲染太慢

我正在DataGridView中绘制我的行,如下所示:

private void AdjustColors()
    {            
        foreach (DataGridViewRow row in aufgabenDataGridView.Rows)
        {
            AufgabeStatus status = (AufgabeStatus)Enum.Parse(typeof(AufgabeStatus), (string)row.Cells["StatusColumn"].Value);

            switch (status)
            {
                case (AufgabeStatus.NotStarted):
                    row.DefaultCellStyle.BackColor = Color.LightCyan;
                    break;
                case (AufgabeStatus.InProgress):
                    row.DefaultCellStyle.BackColor = Color.LemonChiffon;
                    break;
                case (AufgabeStatus.Completed):
                    row.DefaultCellStyle.BackColor = Color.PaleGreen;
                    break;
                case (AufgabeStatus.Deferred):
                    row.DefaultCellStyle.BackColor = Color.LightPink;
                    break;
                default:
                    row.DefaultCellStyle.BackColor = Color.White;
                    break;
            }
        }        
    }
Run Code Online (Sandbox Code Playgroud)

然后我在OnLoad方法中调用它:

protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            AdjustColors();           
        } 
Run Code Online (Sandbox Code Playgroud)

我更喜欢OnLoad到OnPaint或者其他东西......因为OnPaint经常被调用.

问题:为什么改变每行的背景需要大约100-200毫秒?早,我是doint CellPaint ..但滚动时刷新我有问题..

c# datagridview winforms

9
推荐指数
1
解决办法
7543
查看次数

将消息发送到我的机器上的消息队列.....错误"无效的队列路径名称"

我正在向运行Windows Server 2008 R2的计算机上创建的非常标准的消息队列发送消息.

QueueName:
directionsTest
MachineName:
usernameDev
Run Code Online (Sandbox Code Playgroud)

当我尝试将消息发送到队列时,我收到错误.:

队列路径名无效.

我感到困惑的是,我实际上是通过SSMS查询窗口发送此消息,我们有存储过程将这些消息发送到队列,我们​​只提供机器名称,队列名称和消息.所以,这基本上是我多次使用的保存查询,实际上我在上周末使用了这个完全相同的查询.从那时起,我没有更改查询/我的机器/队列/,并且创建和发送这些消息的存储过程没有改变.所以,我不确定为什么这会给我这个错误.

我已经尝试了太阳下的一切,我尝试在我的计算机上创建新的队列并收到相同的错误.我还确保每个人都可以访问这些队列.关于什么会导致此错误弹出的任何想法?我已经搜索过网络,但我没有发现可能导致此问题的线索.(**我还测试了在不同服务器上发送到队列,这没有错误)

感谢任何建议/方向提前.

msmq message-queue

9
推荐指数
1
解决办法
1万
查看次数

在 net core 2.2 中隐藏 swagger 不良响应示例模型

我将我的 netcore 2.1 项目升级到 2.2 并且我的 swagger 页面有问题。

以前在 swagger bad response 中,它只显示没有模型的“错误请求”。

但是在我升级到 net core 2.2 后,错误请求示例中显示了一个模型。下图。

我如何隐藏它以便它只显示“错误的请求”。

我已经使用 CustomApiConvention 进行了测试,但到目前为止还没有成功。

    [HttpGet("{id}")]
    [ProducesResponseType(StatusCodes.Status204NoContent)]
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
    [ProducesResponseType(StatusCodes.Status404NotFound)]
    [ProducesDefaultResponseType]
    public async Task<ActionResult<Employee>> GetEmployee(int id)
    {
        var employee = await _context.Employee.FindAsync(id);

        if (employee == null)
        {
            return NotFound();
        }

        return employee;
    }
Run Code Online (Sandbox Code Playgroud)

我如何隐藏它以便它只显示“错误的请求”?

在此处输入图片说明

c# swagger-2.0 asp.net-core-2.2

9
推荐指数
1
解决办法
2555
查看次数

在 C# WinForms .NET 6 中创建图表

因此,我尝试在 .NET 6 WinForm 应用程序中创建图表,但在工具箱中找不到图表选项。有谁知道它为什么这样做?他们删除了 .NET 6 中的图表吗?如果是这样,我该如何创建图表?谢谢

c# charts winforms .net-core

9
推荐指数
1
解决办法
1万
查看次数

强类型的Windows窗体数据绑定

我正在研究使用扩展方法的强类型Windows窗体数据绑定.我从Xavier那里得到了以下的帮助,如下所示:

using System;
using System.Linq.Expressions;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public static Binding Add<T>
        (this ControlBindingsCollection dataBindings,
            object dataSource,
            Expression<Func<Control, object>> controlExpression,
            Expression<Func<T, object>> objectExpression)
    {
        return Add(dataBindings, dataSource, controlExpression, objectExpression, false);
    }

    public static Binding Add<T>
        (this ControlBindingsCollection dataBindings,
            object dataSource,
            Expression<Func<Control, object>> controlExpression,
            Expression<Func<T, object>> objectExpression,
            bool formattingEnabled)
    {
        string controlPropertyName = ProcessExpression(controlExpression.Body);
        string bindingTargetName = ProcessExpression(objectExpression.Body);

        return dataBindings
            .Add(controlPropertyName, dataSource, bindingTargetName, formattingEnabled);
    }

    public static Binding Add<T, K>
        (this ControlBindingsCollection dataBindings,
            object dataSource,
            Expression<Func<K, object>> …
Run Code Online (Sandbox Code Playgroud)

c# data-binding functional-programming winforms

8
推荐指数
2
解决办法
2629
查看次数

需要帮助来停止BackgroundWorker线程

需要帮助来停止BackgroundWorker线程.我试图阻止后台工作线程.这就是我在做的事情:

在停止按钮单击(UI图层):

if (backgroundWorker.IsBusy == true && 
    backgroundWorker.WorkerSupportsCancellation == true)
{
    backgroundWorker.CancelAsync();
}
Run Code Online (Sandbox Code Playgroud)

在DoWork事件(UI层)上:

if ((backgroundWorker.CancellationPending == true))
{
     e.Cancel = true;
}
else
{
    //Function which progresses the progress bar is called 
    //here with its definition in business layer 
}
Run Code Online (Sandbox Code Playgroud)

一旦DoWork事件被触发并且我的程序控件在Business层中定义的函数中,我如何恢复到DoWork事件以设置'e.Cancel = true'?

c# window

8
推荐指数
1
解决办法
7200
查看次数

8
推荐指数
1
解决办法
1万
查看次数

覆盖更改返回类型的方法

我有一种情况,我想覆盖基类的方法,以略微改变方法的返回类型.通过稍微改变,我的意思是返回一个继承自对象的对象,该对象将由基类型中的方法返回...实际上,一些代码会使这更容易...

class Program
{
    static void Main(string[] args)
    {
        var obj = new ParentClass();
        Console.WriteLine("Parent says: " + obj.ShowYourHand());

        var obj2 = new ChildClass();
        Console.WriteLine("Child says: " + obj2.ShowYourHand());

        Console.ReadLine();
    }
}

public class ParentClass
{
    public string ShowYourHand()
    {
        var obj = GetExternalObject();
        return obj.ToString();
    }
    protected virtual ExternalObject GetExternalObject()
    {
        return new ExternalObject();
    }
}

public class ChildClass : ParentClass
{
    protected virtual new ExternalObjectStub GetExternalObject()
    {
        return new ExternalObjectStub();
    }
}

public class ExternalObject
{
    public override …
Run Code Online (Sandbox Code Playgroud)

c#

7
推荐指数
1
解决办法
2万
查看次数

OpenQA.Selenium.WebDriverException : 抛出一个空响应异常并停止 selenium 测试运行

我正在使用 firefox webdriver 运行 firefox 41.0.2 Nunit 3.4.1 selenium 2.47.0 specflow 2.1.0 我的测试并行运行。

几天过去了,我的测试在通过 jenkins 运行时未能完成,运行卡在一个进程上并且无法继续运行的其余部分。在运行 20 多个场景时,我间歇性地能够在本地重现错误。我收到以下异常,以前有人见过这个问题吗?

OpenQA.Selenium.WebDriverException :抛出一个带有空响应的异常,将 HTTP 请求发送到远程 WebDriver 服务器的 URL http://localhost:7056/hub/session/d0a83b9c-bd79-4218-8eac-dc8b273f8f40/element/% 7B84966a91-06c4-42dd-98c0-278ed35e3667%7D/属性/值

异常状态为 ConnectFailure,消息为:无法连接远程服务器 ----> System.Net.WebException : 无法连接远程服务器 ----> System.Net.Sockets.SocketException : 无法建立连接,因为目标机器主动拒绝它 127.0.0.1:7056

+++++++++++++++++++ 堆栈跟踪:在 OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) 在 OpenQA.Selenium.Firefox.FirefoxDriverCommandExecutor.Execute(Command commandToExecute)在 OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary 2 parameters) at OpenQA.Selenium.Remote.RemoteWebElement.GetAttribute(String attributeName) at TeamHours.Automation.StandAlone.WebComponents.Pages.WeeklySalesForecastPage.<Save>b__0(IWebElement s) in c:\Program Files (x86)\Jenkins\jobs\Automation Build Develop\workspace\TeamHours.Automation.StandAlone.WebComponents\Pages\WeeklySalesForecastPage.cs:line 38 at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() 在 System.Linq.Enumerable.Any[TSource](IEnumerable1 source, Func2 谓词)在 TeamHours.Automation.StandAlone.WebComponents.Pages.WeeklySalesForecastPage.Save() in c:\Program Files (x86)\Jenkins\jobs\Automation Build …

c# selenium

7
推荐指数
2
解决办法
2万
查看次数