Winston Posted February 19, 2003 Posted February 19, 2003 i have a form it hasa button click on it a font dialog appears user selects it then the font is applied to be preivewd in a label and then the font name displayed once the user clicks on apply the font is applied to the main form i.e. mainform.font = fontdialog.font this is what i put in the appply button dim mainform as new frmmain mainform.font = fntdlg.font what happens is it keeps creating new main forms and loading and my system tray has like 20 billion of the app opened i have no way of doing it any way u guys?
*Gurus* divil Posted February 19, 2003 *Gurus* Posted February 19, 2003 Because on this line: dim mainform as new frmmain You are creating a new instance of your main form. You don't want to do this, you want to refer to the instance which is already there. There are many ways to do this, the most common of which is to pass it in the constructor of your options form: Dim f As New frmOptions(Me) Then your options form can retain that object to refer to the already open form. MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Winston Posted February 19, 2003 Author Posted February 19, 2003 woh u totally lost me hehe where do i apply that code?
*Gurus* divil Posted February 19, 2003 *Gurus* Posted February 19, 2003 In your first form, when you create the instance of the options form. I suggest you go and read about constructors in the help system. MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Winston Posted February 19, 2003 Author Posted February 19, 2003 sorry im really bad with programming im just trying to implement most of the features its for my major assignment i have no idea wat im reading so yea
Guest mutant Posted February 23, 2003 Posted February 23, 2003 Show me the code that calls the form with dialog please.
Winston Posted February 23, 2003 Author Posted February 23, 2003 ok the mainform opens the font dialog from a menu item the code as is.. Private Sub mnuFormatAppBaseFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFormatAppBaseFont.Click Dim appbasefont As New frmAppBaseFont() appbasefont.ShowDialog() End Sub where appbasefont is the font form now the font form has a button , once u click on it out comes a font dialog box, user selects a font, and then they get a preview of it in a label and the name of the selected font in a text box, this is the code for the browse button which opens a font dialog fntAppBase.ShowDialog() lblPreviewBox.Font = fntAppBase.Font txtFontSel.Text = fntAppBase.Font.Name btnApply.Enabled = True ok now when the user clicks apply the selected font the user has chosen is changes the main forms font
Guest mutant Posted February 23, 2003 Posted February 23, 2003 Sorry but i ran out of ideas everything i try doesnt work.
Winston Posted February 23, 2003 Author Posted February 23, 2003 i knew it its unsolvable see!! wat about my other probs
Guest mutant Posted February 23, 2003 Posted February 23, 2003 Ill get you a sample of creating a registry key in one sec :)
Guest mutant Posted February 23, 2003 Posted February 23, 2003 Ok: First put Imports Microsoft.Win32 on top of the code Dim key As RegistryKey Dim subkey As RegistryKey key = Registry.LocalMachine subkey = key.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run\") subkey.SetValue("ProgramName", "ProgramPath") Call subkey.Close() Call key.Close()
Winston Posted February 23, 2003 Author Posted February 23, 2003 how exactly do i use it? im doing it via a check box
Guest mutant Posted February 23, 2003 Posted February 23, 2003 By checkbox? You mean that if user checks the check box and presses a button the program will start with windows?
Winston Posted February 23, 2003 Author Posted February 23, 2003 yea its within my options should i just do a select case on the ok button and case true then add blah blah or case false delete key how do i remove the key?
Guest mutant Posted February 23, 2003 Posted February 23, 2003 Change the previous code to: Dim key As RegistryKey Dim subkey As RegistryKey key = Registry.LocalMachine subkey = key.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run\ProgramName") subkey.SetValue("ProgramName", "ProgramPath") Call subkey.Close() Call key.Close() And here is one that will delete it: Dim key As RegistryKey key = Registry.LocalMachine key.DeleteSubKeyTree("SOFTWARE\Microsoft\Windows\CurrentVersion\Run\ProgramName\") Call key.Close()
Winston Posted February 23, 2003 Author Posted February 23, 2003 cool got that underway now the splash screen is the last of my questions besides the font
Guest mutant Posted February 23, 2003 Posted February 23, 2003 Try this: Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim f As New Form2() Timer1.Enabled = False f.Show() End Sub
Winston Posted February 23, 2003 Author Posted February 23, 2003 (edited) ok currently the splash form is set as the start up object the form has a timer once the form loads the timer gets executed and the timer has the following code dim counter as integer counter +=1 if counter =3 then me.close dim mainform as new frmmain mainform.show end if Edited February 24, 2003 by divil
Guest mutant Posted February 23, 2003 Posted February 23, 2003 Is that in the timer event? If it is just use what i said before and set interval to 3000. Also i think that you program ends before you get the main form showed because you closed the only form of app before you open new one.
Winston Posted February 23, 2003 Author Posted February 23, 2003 ahhh yes umm i dont get ur code how would the timer tick wen its not even enabled since its getting enabled in itself :S
Guest mutant Posted February 23, 2003 Posted February 23, 2003 When you drag the timer into your form, set the interval of timer to 3000 cause you 3 seconds right,set enabled to true. In the code: when timer reaches 3 seconds you have to turn it off by putting enabled = false so it wont continue, otherwise you would get a new form shown every 3 seconds instead of once.
Guest mutant Posted February 23, 2003 Posted February 23, 2003 Oh, now when i reread your post i think i get what you ask and how would it tick. The tick event will be executed when timer reaches the interval. So when it ticks after reaching the interval you have to disable it so it wont tick again and show another form.
Cywizz Posted February 24, 2003 Posted February 24, 2003 I've attached a example for the Font problem.... as requestedfontexample.zip Howzit??
Winston Posted February 24, 2003 Author Posted February 24, 2003 cywizz it isnt how i wanted it i got a mainform and a font form mainform has a menu user clicks on it and it opens up the font form on the font form theres a browse button once the user selects the font from the browse button whcih opens a font dialog then they get a preview and the fonts name in a label on the font form then they can click apply and the mainforms font will be changed to wateva they desire
Recommended Posts