This is a migrated thread and some comments may be shown as answers.

use of dialogtype FONT

4 Answers 182 Views
BrowseEditor
This is a migrated thread and some comments may be shown as answers.
pierre-jean
Top achievements
Rank 1
Veteran
Iron
pierre-jean asked on 20 Nov 2019, 02:33 PM

Hello

I try to use the BrowseEditor in DialogType=FontFialog and I am faced with a few questions:

The value returned is a string ex: "Microsoft Sans Serif; 12pt; style=Bold"

1. How do I convert this string to a font type, taking into account that depending on the culture the size may be shown as 8,5 or 8.5

2. How do I set the initial value of the fonteditor from a fontvariable

4. Selecting "Modern 20, bold, size 8", I get the value: "Modern No. 20; 8,249999pt; style=Bold" (not that I want to use this font but I came across this anomality ,,,)

5. How do I change the initial text "(none)" in a localized text

 

And While I am on the BrowseEditor, in folderBrowseDialog, I select the intial directory on the .value property and it sets it properly but it is not always "visible" how can I insurevisible on the selected folder

 

Thanks in advance

Pierre-Jean

4 Answers, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 22 Nov 2019, 02:45 PM

Hello Pierre-Jean,

Firstly, I would like to kindly ask you to use different support threads for submitting different technical questions and avoid posting all of the questions you have in a single ticket. Each ticket is purposed to have a certain main topic or problem that it solves. Thank you for your understanding.

Straight to your questions:

1. If you want to convert the string you get from the FontDialog to a font type you can use the FontConverter which works fine with both a comma or a dot as a numeric separator depending on what is the set up on your machine. This can be done in the ValueChanged event which fires after the editor's value is changed:

 Font f;
private void RadBrowseEditor1_ValueChanged(object sender, EventArgs e)
{
    fontAsString = this.radBrowseEditor1.Value;
    FontConverter cvt = new FontConverter();
    if (fontAsString != null)
    {
        f = cvt.ConvertFromString(fontAsString) as Font;
    }
}

2. If you want to set an initial value for the FontDialog you should choose an appropriate font and convert it to a string. Then use the Value property:

 FontConverter cvt = new FontConverter();
 Font f = new Font("Arial", 12f, FontStyle.Bold);
 this.radBrowseEditor1.Value = cvt.ConvertToString(f);

3. According to the rounded number that you get it is the default behavior of the standard MS FontDialog. I tested it separately and get the same result in order to ensure that this is not an issue in RadBrowseEditor control.

4. You can change the initial text in the text box by a localization provider for RadBrowseEditor. You can make custom provider which inherits from the RadBrowseEditorLocalizationProvider class and override its GetLocalizedString method where is the appropriate place to change the default text:

RadBrowseEditorLocalizationProvider.CurrentProvider = new MyRadBrowseEditorLocalizationProvider();

public class MyRadBrowseEditorLocalizationProvider : RadBrowseEditorLocalizationProvider
{
    public override string GetLocalizedString(string id)
    {
        if (id == RadBrowseEditorStringId.None)
        {
            return "select font";
        }

        return string.Empty;
    }
}

5. I created a sample project with BrowseEditorDialogType.FolderBrowseDialog and set its initial value. It seems to work properly. Could you please specify in which cases it is not visible on your end. Feel free to modify the provided project in order to reproduce the undesired behavior. Thus, we would be able to investigate the precise case and assist you further.

I hope this information helps. Do not hesitate to contact us if you have other questions.

Regards,
Nadya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 26 Nov 2019, 02:47 PM

Hello 

thanks a lot for your message, I thought it would be simpler to put my various questions in the same topic since it was related to the same control. In the future I will use different topics.

Your message solved all my questions but the one related to the visibility of the selected folder.

I attach a animated screen copy that illustrates the issue.

I select a Folder deep down in my "DEV" folder.
When I get back to the folder selection, the folder is properly selected but the tree node is not in the visible range. I have to scroll down to see the selected Node.

I wonder if there is a possibility to ensure visibility of the selected folde.

Thanks 

0
Nadya | Tech Support Engineer
Telerik team
answered on 28 Nov 2019, 10:42 AM

Hello Pierre-Jean,

RadBrowseEditor uses the standard MS FolderBrowseEditor. After making some research in general programming forums, it seems that this is an already known issue. I have found the following threads suitable for your case:

https://stackoverflow.com/questions/6942150/why-folderbrowserdialog-dialog-does-not-scroll-to-selected-folder
https://stackoverflow.com/questions/705409/how-do-i-open-a-folderbrowserdialog-at-the-selected-folder

For your reference, I created custom RadBrowseEditor and RadBrowseEditorElement in order to implement this functionality by using the SendKeys.Send method as suggested in the first thread I have provided. Please refer to the following code snippet which result is demonstrated in the attached gif file:

 public class CustomBrowseEditor : RadBrowseEditor
 {
     public override string ThemeClassName
     {
         get
         {
             return typeof(RadBrowseEditor).FullName;
         }
     }
     protected override RadBrowseEditorElement CreateEditorElement()
     {
         return new CustomRadBrowseEditorElement();
     }
 }

 public class CustomRadBrowseEditorElement : RadBrowseEditorElement
 {
     protected override Type ThemeEffectiveType
     {
         get
         {
             return typeof(RadBrowseEditorElement);
         }
     }
     protected override void OnBrowseButtonClick(EventArgs e)
     {
         InitializeDialog();
         SendKeys.Send("{TAB}{TAB}{RIGHT}");
         DialogResult result = this.Dialog.ShowDialog();

         if (result == DialogResult.OK)
         {
             bool wasReadOnly = this.ReadOnly;

             this.ReadOnly = false;

             SaveValueFromDialog();

             this.ReadOnly = wasReadOnly;
         }

         this.OnDialogClosed(new DialogClosedEventArgs(result));
     }
 }

I hope this helps. Do not hesitate to contact me if you have other questions.

Regards,
Nadya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 28 Nov 2019, 02:35 PM

Hello thank you for the explanation and the code snippet.

I'll look into it 

Best regards

Pierre-Jean

Tags
BrowseEditor
Asked by
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Share this question
or