Extend window control as custom control problem
-
Hi~ I have encountered a very difficult problem and worked for a long time but still can't solve it. Pls help it. The problem is : There are two cases. One is for .net full vesion, one is for .net compact framework. For the .net full version, "ListViewEx" is a class which extend listView. class ListViewEx : ListView { ListViewEx() { } protected override OnPaint(PaintEventArg e) { MessageBox.Show("ABC"); base.OnPaint(); } The problem is the overriding OnPaint not be executed if a instance of this class newly be created but the base class (I don't know the method (OnPaint()) of the class "Control" or class "ListView" will be called and draw the listview only without showing message box. However, the overriding OnPaint method seems works if the extended window control is not listview but button or panel. (Other control also not work). What is the problem? For the CF case, The case is that the if Class for example "ListViewEx2" extend the class ListView, the overriding Method OnPaint() still not work since the virtual void OnPaint method in the ListView Class is not supported. However, as the ListView extend Control, and the control also got the virtual method OnPaint(), that mean the ListViewEx2 also got the virtual OnPaint method and which can be overrided by ListViewEx2. Then why the overrided method in ListViewEx2 does not executed? Thanks }
-
Hi~ I have encountered a very difficult problem and worked for a long time but still can't solve it. Pls help it. The problem is : There are two cases. One is for .net full vesion, one is for .net compact framework. For the .net full version, "ListViewEx" is a class which extend listView. class ListViewEx : ListView { ListViewEx() { } protected override OnPaint(PaintEventArg e) { MessageBox.Show("ABC"); base.OnPaint(); } The problem is the overriding OnPaint not be executed if a instance of this class newly be created but the base class (I don't know the method (OnPaint()) of the class "Control" or class "ListView" will be called and draw the listview only without showing message box. However, the overriding OnPaint method seems works if the extended window control is not listview but button or panel. (Other control also not work). What is the problem? For the CF case, The case is that the if Class for example "ListViewEx2" extend the class ListView, the overriding Method OnPaint() still not work since the virtual void OnPaint method in the ListView Class is not supported. However, as the ListView extend Control, and the control also got the virtual method OnPaint(), that mean the ListViewEx2 also got the virtual OnPaint method and which can be overrided by ListViewEx2. Then why the overrided method in ListViewEx2 does not executed? Thanks }
OnPaint
is not used by theListView
control, as you could see by disassembling or decompiling the System.Windows.Forms.dll assembly. Almost every control in Windows Forms simply encapsulates the Winodws Common Controls. In the case of some controls likeListView
owner drawing the control simply by overridingOnPaint
is not possible. To owner draw a List-View common control you need to overrideWndProc
, define several custom drawing structures, and P/Invoke several native APIs. For more information about the native List-View common control that is encapsulated by theListView
managed control, see http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/listview/reflist.asp[^]. For examples on this site about owner-drawing aListView
control, see the search http://www.codeproject.com/info/search.asp?cats=3&cats=5&searchkw=ListView[^]. You could also try searching this forum for "ListView" by clicking "Search comments" directly above this message area. We've talked about custom drawing aListView
quite a bit, and I know that I personally have posted several snippets of code that show how to draw certain parts through the custom drawing routines that the native Common Controls use. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]