Results 1 to 7 of 7

Thread: [RESOLVED] [1.0/1.1] Converting

  1. #1

    Thread Starter
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    Resolved [RESOLVED] [1.0/1.1] Converting

    I thought a good way to learn C# would be to re-write all the VB.NET apps i've already written. To start small, i went with a RichText editor, but i can't get the font dialog to work. It shows up, but it won't change the text. Heres the code im using:

    VB Code:
    1. private void fontDialog1_Apply(object sender, System.EventArgs e)
    2.         {
    3.             rtb.SelectionFont = fontDialog1.Font;
    4.         }

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [1.0/1.1] Converting

    The font dialog doesn't return a DialogResult.OK?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [1.0/1.1] Converting

    The Apply event is raised when the user clicks the Apply button on the dialogue, not the OK button. If you haven't set the ShowApply property of the dialogue to True then there is no Apply button and that event can never be raised. Normally you would test the result of ShowDialog and if it is OK then apply the font. If you have set the ShowApply property to True then you would also handle the Apply event and use the same method to set the font. The Apply event is provided because pressing the Apply button does not dismiss the dialogue.
    Code:
            private void button1_Click(object sender, System.EventArgs e)
            {
                if (this.fontDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    // The user pressed the OK button.
                    this.applyFont();
                }
            }
    
            private void fontDialog1_Apply(object sender, System.EventArgs e)
            {
                // The user pressed the Apply button.
                this.applyFont();
            }
    
            private void applyFont()
            {
                this.richTextBox1.SelectionFont = this.fontDialog1.Font;
            }
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    Re: [1.0/1.1] Converting

    Well, i didn't know....the 'private void fontDialog1_Apply' code was generated by the Borland C# builder when i doubled clicked the font dialog.
    Thanks for your replies, you solved my problem.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [1.0/1.1] Converting

    Apply is the default event for the FontDialog, thus a handler is created for it when you double-click it, just like every component. The same would happen in the Microsoft VB IDE. With most dialogues though, it's the return value of ShowDialog that you're most interested in.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    Re: [RESOLVED] [1.0/1.1] Converting

    It funny that its default event is Apply, yet, by default it doesn't add an apply button...

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [1.0/1.1] Converting

    The FontDialog only has two events: Apply and HelpRequest. It doesn't show a Help button by default either, and I guess they judged that Apply would be used more often so that should be the default. I guess you would expect that it would have an event that corresponded to the OK button being pressed, like the FileDialogs do. Not that that event gets used much anyway as most people just test the return value of ShowDialog anyway. It would be a bit more intuitive though.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width