c# - Writing/Drawing my own ListBox/ListView Control from scratch -


how go finding out how windows forms control made? want create control scratch. preferably listbox or better, listview control, have no idea start.

some suggestions i've come across in past have been:

  1. use panel control , dynamically add label controls appropriate styling, and;
  2. extend or subclass listview/listbox controls, , set ownerdraw true, , custom drawing in onpaint event.

but want more control that. don't want listview control, don't want use third-party control either (no matter how [object listview] is1. want my own listview control. don't care how hard is, possible in windows forms? should start?

would need use gdi/gdi+ draw everything? start empty panel control , manually draw each list item using system.drawing namespace?

how go finding out how windows forms control made?

simple, every control window created using createwindowex method (done internally winforms).

in winforms point of view: control base class windows. there controls has been written in unmanaged code listview, listbox etc. them can't see paint code in .net. implemented in os itself(not sure dll live). winforms provides wrapper on unmanaged controls.

but, there purely managed controls written in c#. example: datagridview. can go through code. here master onpaint protected method. place need write custom painting logic graphics instance provided.

key you'll create "datastructure" holds necessary items draw control. lets itemrectangle, text, color, font, etc.. use them paint custom control in onpaint method.

would need use gdi/gdi+ draw everything?

you'll use system.drawing , system.drawing.drawing2d namespaces draw control. if .net doesn't provide you'll p/invoke gdi/gdi+

advice choosing base class: if control needs scrollable(listview kind of controls need it). can choose scrollablecontrol or panel base class supports scrolling. otherwise can inherit control class.

developing custom windows forms controls .net framework

all best :)


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -