דילוג לתוכן
  • דף הבית
  • קטגוריות
  • פוסטים אחרונים
  • משתמשים
  • חיפוש
  • חוקי הפורום
כיווץ
תחומים

תחומים - פורום חרדי מקצועי

💡 רוצה לזכור קריאת שמע בזמן? לחץ כאן!
  1. דף הבית
  2. תכנות
  3. קוד לבוחר פונטים בשביל C#

קוד לבוחר פונטים בשביל C#

מתוזמן נעוץ נעול הועבר תכנות
1 פוסטים 1 כותבים 78 צפיות
  • מהישן לחדש
  • מהחדש לישן
  • הכי הרבה הצבעות
התחברו כדי לפרסם תגובה
נושא זה נמחק. רק משתמשים עם הרשאות מתאימות יוכלו לצפות בו.
  • pcinfogmachP מנותק
    pcinfogmachP מנותק
    pcinfogmach
    כתב ב נערך לאחרונה על ידי pcinfogmach
    #1

    הייתי צריך משהו יותר ממוקד מfontdialog המובנה של windows form
    אולי למישהו אחר גם יהיה מזה תועלת
    יש להוסיף class חדש לפרוייקט להעתיק לתוכו את הקוד כמות שהוא.

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Linq;
    public class CustomFontSelectionDialog : Form
    {
        private ListBox fontListBox;
        private Label previewLabel;
        private Button okButton;
        private TextBox searchBox;
    
        public Font SelectedFont { get; private set; }
    
        public CustomFontSelectionDialog()
        {
            this.Text = "בחר גופן";
            this.Size = new Size(450, 280);
            this.RightToLeft = RightToLeft.Yes;
            this.RightToLeftLayout = true;
    
            searchBox = new TextBox();
            searchBox.Location = new Point(10, 10);
            searchBox.Size = new Size(200, 20);
            searchBox.TextChanged += SearchBox_TextChanged;
            this.Controls.Add(searchBox);
    
            fontListBox = new ListBox();
            fontListBox.Location = new Point(10, searchBox.Bottom + 10);
            fontListBox.Size = new Size(200, 180);
            fontListBox.SelectedIndexChanged += FontListBox_SelectedIndexChanged;
            this.Controls.Add(fontListBox);
    
            previewLabel = new Label();
            previewLabel.Location = new Point(fontListBox.Right + 10, 10);
            previewLabel.Size = new Size(180, this.ClientSize.Height - 2 * 20 - 40); // Adjusted for searchBox and margin
            previewLabel.Font = new Font("Arial", 12);
            previewLabel.Text = "תצוגה מקדימה"; // Sample Hebrew text for preview
            previewLabel.BackColor = Color.White;
            this.Controls.Add(previewLabel);
    
            okButton = new Button();
            okButton.Text = "אישור";
            okButton.Location = new Point(previewLabel.Right - okButton.Width, this.ClientSize.Height - okButton.Height - 20);
            okButton.Click += OkButton_Click;
            this.Controls.Add(okButton);
    
            // Populate the fontListBox with available fonts
            foreach (FontFamily fontFamily in FontFamily.Families)
            {
                fontListBox.Items.Add(fontFamily.Name);
            }
        }
    
        private void SearchBox_TextChanged(object sender, EventArgs e)
        {
            string searchText = searchBox.Text.ToLower(); // Convert search text to lowercase
            fontListBox.Items.Clear();
    
            // Filter and display fonts that match the search text (case-insensitive)
            foreach (FontFamily fontFamily in FontFamily.Families)
            {
                if (fontFamily.Name.ToLower().Contains(searchText))
                {
                    fontListBox.Items.Add(fontFamily.Name);
                }
            }
            //fontListBox.SelectedIndex = 0;
        }
    
        private void FontListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selectedFontName = fontListBox.SelectedItem as string;
            if (selectedFontName != null)
            {
                SelectedFont = new Font(selectedFontName, 12); // Set a default size
                previewLabel.Font = SelectedFont;
            }
        }
    
        private void OkButton_Click(object sender, EventArgs e)
        {
            // The user has selected a font, you can use the SelectedFont property here.
            DialogResult = DialogResult.OK;
            this.Close();
        }
    
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new CustomFontSelectionDialog());
        }
    }
    
    

    וזה הקוד שלי לפתיחת הבוחר פונטים
    שימו לב: אפשר להשתמש עם זה כדי להגדיר פונט בתוכנה שלכם על ידי שימוש ב resources >Settings שם תוכלו להגדיר משתנה שישמור את שם הפונט שהשתמשתם בו כמוצג בקוד דלהלן.

    private void chooseFontForBooks_Click(object sender, EventArgs e)
    {
        using (CustomFontSelectionDialog fontDialog = new CustomFontSelectionDialog())
        {
            if (fontDialog.ShowDialog() == DialogResult.OK)
            {
                Properties.Settings.Default.fontName = fontDialog.SelectedFont.Name;
                Properties.Settings.Default.Save();
            }
        }
    }
    

    גמ"ח מידע מחשבים ואופיס

    תגובה 1 תגובה אחרונה
    2

    בא תתחבר לדף היומי!
    • התחברות

    • אין לך חשבון עדיין? הרשמה

    • התחברו או הירשמו כדי לחפש.
    • פוסט ראשון
      פוסט אחרון
    0
    • דף הבית
    • קטגוריות
    • פוסטים אחרונים
    • משתמשים
    • חיפוש
    • חוקי הפורום