Winston Posted February 24, 2003 Author Posted February 24, 2003 wow its rite!!!! thats how i wanted it thx im not getting how u get the _parent thing and _selected font tow rokwhere u declare it?
Cywizz Posted February 24, 2003 Posted February 24, 2003 look under the region "Class Variables". I've declared it there. Howzit??
Winston Posted February 24, 2003 Author Posted February 24, 2003 hmm i copied the class variables in and the little code for the apply button in my project it aint working too well :S i get object reference error
Cywizz Posted February 24, 2003 Posted February 24, 2003 I assume you're getting the error on the click event of the apply button..... Have you created the new constructer with the parent reference, and did you set the passed in form to the local _parent variable? Try to understand what I did, rather than copying the code....Once you understand these concepts(constructors/overloading/object refs) you will find it a lot of fun, and you never will want to go back to vb6 :o Howzit??
Winston Posted February 24, 2003 Author Posted February 24, 2003 i still am not understanding it too well read it over and over tried to replicate it first to get it working didnt work copied region constructor and class variables and also bounded it by the region events
Cywizz Posted February 24, 2003 Posted February 24, 2003 You cant just copy the example code and expect it to work. Understand my example in context of yours, and apply the best solution based on that. btw, you can't just copy the events, because I'm using my own control names... It looks like the events isn't firing... try to step through your code Howzit??
Winston Posted February 24, 2003 Author Posted February 24, 2003 im confused in terms of regions and stuff..
Cywizz Posted February 24, 2003 Posted February 24, 2003 Ok, forget about regions... regions are just a way of grouping your code (part of documentation...) Step through your code... that is the ONLY way you can determine where and what the problem is... Howzit??
Winston Posted February 24, 2003 Author Posted February 24, 2003 (edited) i see zero errors wrong with my code stepped through it all went through the windows generated form code this is the code for the font form #Region "Constructor" Public Sub New(ByVal parent As Form) 'fire other constructor Me.New() 'set the module level variable _parent = parent End Sub #End Region #Region "Class Variables" Private _parent As Form Private _selectedFont As Font #End Region #Region "Events" Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click Me.Close() End Sub Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click fntAppBase.ShowDialog() _selectedFont = fntAppBase.Font lblPreviewBox.Font = _selectedFont txtFontSel.Text = _selectedFont.Name btnApply.Enabled = True End Sub Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApply.Click _parent.Font = _selectedFont End Sub Private Sub frmAppBaseFont_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click _parent.Font = _selectedFont Me.Close() End Sub #End Region End Class Edited February 24, 2003 by divil
Cywizz Posted February 24, 2003 Posted February 24, 2003 hmm i copied the class variables in and the little code for the apply button in my project it aint working too well :S i get object reference error so where does the error occur? The only problem I see is when the cancel button was clicked on the fontdialogbox (_selectedFont will be nothing) Howzit??
Winston Posted February 24, 2003 Author Posted February 24, 2003 it occurs wen i click on the apply button object reference not set to an instance of an object
Winston Posted February 24, 2003 Author Posted February 24, 2003 ok i finally got it it was all the main forms fault the dim frmfnt as new frmfont () i missed the (me) out wat does that do? the me
Cywizz Posted February 24, 2003 Posted February 24, 2003 It passes the mainforms reference (me) into the fontform (via the constructor). This reference is then set to the variable: _parent. Read up on constructors and overloading, it will explain it better. Cheers! Howzit??
Winston Posted February 24, 2003 Author Posted February 24, 2003 thanks i got most of the box underway one last error free thing i need to do is checking the cancel button say the font form is loaded and the user opens the font dialog they selected a font and then clicked cancel and clicked on OK it applied still :S.... how do i control the cancel button so it does nothing
Cywizz Posted February 24, 2003 Posted February 24, 2003 I'm going to draw the line here... this problem should be solved by even the novice of vb6 developers. I do suggest, as divil did, to get yourselve a proper vb.net book. I used, and recommend, Professional VB.NET - ISBN 1-861004-97-4 Cheers! Howzit??
Recommended Posts