Unable to create new System.Drawing.Font from FontButton FontName-GTK-Mono

maxtormaxtor INMember

Im using the following code to select a font using the font button -font selection event(GTK )and create a System.Drawing.Font

protected void OnFontbutton2FontSet (object sender, EventArgs e)
        {


            try{

                string sfont = fontbutton2.FontName; 

                string fontName=sfont.Substring(0,sfont.LastIndexOf(' '));

                int fontSize=int.Parse(sfont.Substring(sfont.LastIndexOf(' ')+1).Trim());// I know, looks a bit ugly 
                cfont=new Font(fontName ,fontSize, FontStyle.Regular,System.Drawing.GraphicsUnit.Pixel);
                selectedfont=new Font(fontName ,fontSize, FontStyle.Regular,System.Drawing.GraphicsUnit.Pixel);
                MessageDialog md = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, fontName);
                int result = md.Run ();
                MessageDialog md2 = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, selectedfont.Name);
                int result2 = md2.Run ();
                if (wwork.IsBusy == false) {

                    wwork.RunWorkerAsync ();

                } else {
                    bgdirty = true; 
                }
            }
            catch(Exception error) {

            }

        }

But the newly created font object stays as the default font,only the font size changes .. font does not change.What I'm i doing wrong.
Please advice.

Posts

  • ChrisHamonsChrisHamons Xamurai USForum Administrator, Xamarin Team Xamurai

    So this forum is primarily for Xamarin.Mac users. I don't happen to know anything about System.Drawing or GTK, so I can't help you, nor is it likely most of the regular contributors will be able to.

  • kooperkooper USMember

    @ChrisHamons I cannot create a Font like this by specifying the name of the font (which shows in the FontChooser)

    System.Drawing.Font cfont=new Font("Tahoma","10", FontStyle.Regular,System.Drawing.GraphicsUnit.Pixel);

    So Xamarin.Mac does not support System.Drawing? Please advice

  • ChrisHamonsChrisHamons Xamurai USForum Administrator, Xamarin Team Xamurai

    Please see this new FAQ for details on System.Drawing and Xamarin.Mac - https://forums.xamarin.com/discussion/68261/system-drawing-and-xamarin-mac-faq

Sign In or Register to comment.