相关疑难解决方法(0)

如何避免成千上万不必要的ListView.SelectedIndexChanged事件?

如果用户选择.NET 2.0 ListView中的所有项目,ListView将为每个项目触发SelectedIndexChanged事件,而不是触发事件以指示选择已更改.

如果用户然后单击以选择列表中的一个项目,则ListView将为未选中的每个项目触发SelectedIndexChanged事件,然后为单个新选择的项目触发SelectedIndexChanged事件,而不是触发事件以指示选择已经改变.

如果您在SelectedIndexChanged事件处理程序中有代码,当您开始在列表中有几百/千个项目时,程序将变得非常无响应.

我考虑过停留计时器等.

但有没有人有一个很好的解决方案,以避免成千上万的不必要的ListView.SelectedIndexChange事件,什么时候真的会有一个事件呢?

.net listview selectedindexchanged winforms

16
推荐指数
1
解决办法
8070
查看次数

什么可能导致双缓冲杀死我的应用程序?

我有一些使用GDI +绘制到屏幕的自定义(winforms)组件.

为了防止重绘时出现闪烁,我决定启用双缓冲,所以我在构造函数中添加了一行:

public ColourWheel()
{
    InitializeComponent();
    this.DoubleBuffered = true;
}
Run Code Online (Sandbox Code Playgroud)

哪个适用于此组件(ColourWheel).当我将相同的行添加到我的另外两个(结构相似的)组件的构造函数中时,我会得到一些奇怪的症状:

  1. 当我尝试运行组件打开的表单时,我得到一个Argument Exception Application.Run(new Form());.
  2. 如果我切换到设计模式,我得到一个错误,关于具有未处理异常的组件与参数.

我是否对其中一个或全部进行双缓冲似乎并不重要,它仍然适用于ColourWheel,但不适用于其他.

为了记录,我还尝试了一些其他的 缓冲技术.

什么可能导致双缓冲在一个组件上工作,而不是其他组件?


编辑:这是运行时症状的异常细节:

System.ArgumentException未处理Message = Parameter无效.Source = System.Drawing StackTrace:System.Drawing.Graphics.GetHdc(),位于System.Windows.Forms.Control的System.Drawing.BufferedGraphics.Render()的System.Drawing.BufferedGraphics.RenderInternal(HandleRef refTargetDC,BufferedGraphics缓冲区)中.系统中System.Windows.Forms.UserControl.WndProc(Message&m)的System.Windows.Forms.ScrollableControl.WndProc(Message&m)处的System.Windows.Forms.Control.WndProc(Message&m)处的.WmPaint(Message&m) .Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam, IntPtr lparam)在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&msg)处于System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32 reason,Int32 pvLoopData)at at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason,ApplicationContext context),位于TestForm.Program.Main()的System.Windows.Forms.Application.Run(Form mainForm)的System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,ApplicationContext context)中D:\ Documents and Settings\Tom Wright\My Documents\Visual Studio 2010\Projects\ColourPicker\TestForm\Program.cs:在System.AppDomain.ExecuteAssembly的System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String [] args)的第18行(String assemblyFile,Evidence assemblySecurity,String [] args)在System.Threading.ExecutionContext.Run的System.Threading.ThreadHelper.ThreadStart_Context(Object state)中的Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()(ExecutionContext executionContext,ContextCallback callback) System.Threading.ThreadHelper.ThreadStart()InnerException上的System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态),对象状态,布尔值ignoreSyncCtx):


编辑2:导致问题的两个组件中的一个(更复杂)的OnPaint处理程序:

private void ValueSlider_Paint(object sender, PaintEventArgs e)
{ …
Run Code Online (Sandbox Code Playgroud)

c# components gdi+ double-buffering

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