开发者

vb.net getsettings

开发者_StackOverflow社区I need a form width a checkbox "Don't show this again" for my winform, but how can i make this so when my Form1 loads it checks the state of the checkbox using the getsettings option?

How can is save the checkbox state to the registery? and how do i get the state?

    If Form2.Checkbox.checked = Getsettings() Then 
Form2.showdialog
    Else
Goto Skip
End IF

Skip:


Windows Forms has built-in support for that, you don't need to write any code. Select your check box. In the Properties window, scroll to the top on expand the "ApplicationSettings" node. Click on "Checked" and drop-down the combobox. Click New. Set the Name property to something meaningful.

Done. Your check box will always restore with the last selection that the user selected. Don't call Show() when it is turned on, dispose the form right away.


The main crux of the question is "how do I read and write value to and from the registry."

See here for a great overview complete with code.

You're beginner so here are a few tips on your code sample:

  • Name your objects more verbosely. Form2 will mean nothing to you a few hours from now.
  • Do not use Goto. Just don't. Please. You either show the dialog or you don't. The whole Else block with the Goto in it is just not necessary.

Few more things you'll need to do to get this working:

  1. Handle the CheckBox checked event and write either a 1 or 0 (or T or F) to a registry value
  2. Read that registry value in your GetSettings method
  3. You might want to pass a parameter to GetSettings that specifies exactly which setting you need because you'll probably want to reuse that method for other settings as well
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜