vb.net - How to access buttons on a parent form from a child form which inherits it -



vb.net - How to access buttons on a parent form from a child form which inherits it -

i made windows form in vb.net has panel datagridview on it, , underneath flowlayoutpanel save , close buttons on it, phone call frmparent. created frmchild , on inherited frmparent. hooked datagridview info , worked fine.

next tried add together code save changes datagrid , buttons locked. checked modifiers: both buttons , flowlayoutpanel contains them protected. read there problems accessing controls contained in collection of control. datagridview fine, question:

what need save , cancel buttons available on kid form? need away flowlayoutpanel, or there way? in simple illustration isn't big of deal, start using visual inheritance regularly , know best way things.

something ?

public class frmparent private sub button_saveclick(sender object, e eventargs) buttonsaveclicked(...) ' pass here argument want (e, sender, anything...) end sub protected overridable sub buttonsaveclicked(...) ' here frmparent should upon button_save click... end sub end class public class frmchild inherits frmparent protected overrides sub buttonsaveclicked(...) ' same arguments ' here frmchild should upon button_save click... ' phone call mybase.buttonsaveclicked(...) ' if want frmparent deed aswell... end sub end class

edit : next parts of question :

dissociating user interface , object datas passing instance of object or not ?

i'm no expert on programming, i've read 1 interresting thing user interface/object.

what come mind first talking user interface blog post (don't recall link, sorry) talking windows way of programming , linux way. before starting drift off topic ride, want create clear don't care linux vs windows , i'm not interrested in such debate. want share remember blog post :

in windows programming, first thing think of (and invited do) create user interface : windows form (or window in wpf) you'll create objects manipulated through interface. in linux programming, it's inverse : you'll create first objects should able do, , after you'll think of user interface "enhance" way manipulate them.

^^ or alike.. i'm 0 linux knowledge, can't compare, assume above true, mostly. , reckon since oop existed, "windows way" of programming (that i'm used to) has lot of drawbacks , messy code : you're asking wether specific part of code should enclosed in object or in user interface.

so, i've come thought of mine, may stupid, i'm fine with. started seek "linux way"... @ least, "the way i'm thinking linux programmer it"

let's take command called datagridview. can contain text, dropboxes, buttons, images, etc. i'm not digging in bounding dataset maintain simple. basically, datagridview object having manipulate above sub-objects within it. unfortunately, string, or image not (visual) control, while dropbox, or button is. have typical case of windows created object (datagridview) melting pot of datas , user interface, don't have object handles info part of datagridview, , object handles visual user interface of thing (or @ least, i'm not aware of such objects in .net) afaik you're forced handle both info , user interface when using dgv !

so created class , called table_class can contain such objects (that not controls) string, bitmap, list (of string), xml... contained datas binary coded.

then created form, , called table_form, can display content of table_class. edits functions , methods members of table_class. if want order grid columns, it's class through 1 of inbuilt function.

of course, i'm not here show i'm wasting time reinvent wheel, know i'm doing wrong approach required fact i'm dealing massive amound of various datas loaded from files , saved as files. i'm glad have own class of datas , happy extends capabilities when want.

the main purpose of blabla illustrate sentiment passing entire class or some of members form. in tandem table_class/table_form, of course, i'm passing entire table_class on table_form , vice versa. in fact, it's 2 different thing can used @ same time, or 1 @ time :

' sample code : entire classes takes several files... public partial class table_class ' here object invisible user private _containerform table_form = nil public sub showform(optional byval ownerform form = nothing) if _containerform nil _containerform = new table_form(me) end if if ownerform nil _containerform.show() else _containerform.show(ownerform) end if end sub public sub new() end sub public sub new(byref newcontainerform table_form) _containerform = newcontainerform _containerform.settable(me) end sub end class

and here (associated) form (constructor , associated object initialization)

public partial class table_form private _selectedtable table_class = nil public sub settable(byref newtable table_class) removehandlers() ' table_class has events. ' if _selectedtable not nothing, ' remove handlers prior redefining new selected table. _selectedtable = newselectedtable _selectedtable.setcontainerform(me) initializehandlers() ' add together handlers ui updates upon table_class edits. end sub public sub new() end sub public sub new(byref newselectedtable table_class) settable(newselectedtable) end sub end class

as can see, can manipulate table_class either in background when user shouldn't care content, or via user interface. datagridview, must take care of visual appearance in order build output data/dataset/database.

what of import note here from moment want visual display of object through user interface, must pass critical members of object displaying interface. can't avoid doing @ moment or another. in example, i've passed entire table_class since i'm doing every info modification in class.

the difference datagridview :

with dgv, when edit 1 (string) entry in cell using keystrokeorf2, value stored in cell of dgv, then, either application straight sends programatically value associated database, either have save button or save menu update edits. with table_class, of course of study i'm using datagridview display contents, , have save button on toolbar , in menuitem. when click on buttons, save method not in table_form form. save method method belonging table_class itself.

that's illustration lies separation between visual interface (of datagridview/form) , object containing datas.

i know table_class/table_form illustration complex one, way understand half of secund part of question in original post : "how separate user interface , data/object manipulation"

the answer : it's ! think have similar ways of doing : table_class blackbox class. table_form shows datas , parent/child form does.

i assume remaining half of issue : "i can't phone call blackbox.savechanges click method of button when in flowlayoutpanel". that's not related object/user interface limits syndrome, , exclusively different issue. that's main purpose of reply before long edit : suggested workaround calling method (buttonsaveclicked()) instead of writing save part of code direclty under button_saveclick() method handles click. don't know if approach worked "locked" button or not.

back user interface/object thing : comes above : "you must pass critical members of object user interface @ point", , critical fellow member must object (with critical datas want manipulate, in case, assume info save) in table_class/table_form example, i've passed entire table_class in table_form :

public partial class table_form private _selectedtable table_class ' ... end class

so when want table_class (object containing info manipulate) save edits, through table form (form acting user interface) have methods sets in form :

public partial class table_form private sub menu_main_file_saveclick(byval sender object, byval e eventargs) ' menustrip -> file -> save savetable() end sub protected sub toolbar_main_saveclick(byval sender object, byval e eventargs) ' save button shortcut on toolbar. savetable() end sub ' ^^ both controls calls same method savetable() ' similar buttonsaveclicked method suggested ' savetable ? protected overridable sub savetable() if _selectedtable isnot nil _selectedtable.save(true) end if ' calls table_class.save(... arguments) end sub ' ... end class

in end, code handling how datas should saved doesn't exists in user interface. save changes, table_class object has handfull set of save(...) methods handle extension saveas (opens savefiledialog), overwrite without prompt, save binary or save textual... , if want more extensions sending datas on web, in database, or packing/unpacking table contents in directory, have implement in object (table_class) , visual part handled in form, same way did start.

so when inquire me "wouldn't end child-specific code in parent form way?" : "it's you". i've decided table_class : info loading/parsing, info updating and info saving. if @ time in future have implement new way of saving datas, have selection add together overload of save() method of table_class, or building specific save method in form application using table_class if want. , that's possible because table_class :

is not user interface has associated user interface in case it's required while has read , write datas to, programmatically. and yes, i'm passing entire table class in ui, no matter it's parent 1 or kid form utilize inheritance.

i think "having messed parent/child code in user interface side" highly depends on capabilities of non user interface object (should) manipulate datas.

(actually, table class not single table. it's node of tree of tables, or table contains datas, , tables children contains other datas each. can think of merger of datagridview , treeview, that's why private variable united nations ui form named _selectedtable.) i'm mentioning lastly complexity of table_class notify no matter how complex object is, it's easy utilize whatever user interface use, because there isn't single visual code in object, , there little code manipulating datas in user interface (all ui read datas object, display/edit or utilize them other purposes, , send validated modifications object, phone call object.save())

i've made long explaination of way i'm doing allow have latitude decide how want application behave, blackbox class should able accomplish alone , limits of user interface. there no simple reply analysis, , highly depends on going utilize application purpose; if have deadlines, maintain simple, if goal requires complex , highly manipulable datas, i think should not mix user interface code , info manipulation code; hell alter if have upgrade class new features @ later time.

sorry long post. i'm french speaking , don't know if english language okay. don't mind blabla, that's me, can't maintain thought in mind without telling in details.

try buttonsaveclicked() phone call workaround. worked me flow layout panel : i've made overridable buttonsaveclicked() in parent form message box saying "hello", , override buttonsaveclicked() in kid form saying "coucou", , worked well. can create variable containing blackbox object in parent form did table_form, , way create accessible kid form (protected, or public property or set of protected methods , functions, don't know...) decide blackbox members (properties, methods, functions, events...) , how should/could used parent , kid forms.

vb.net winforms inheritance

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -