PotatOBiTz
PotatOBiTz
CC#
Created by PotatOBiTz on 7/12/2023 in #help
✅ Changing the individual font of items in a Combo Box - C# Windows Forms
This has been troubling me since this morning. And it was the work of one setting Thanks for the help :3
24 replies
CC#
Created by PotatOBiTz on 7/12/2023 in #help
✅ Changing the individual font of items in a Combo Box - C# Windows Forms
Aaaah there we go
24 replies
CC#
Created by PotatOBiTz on 7/12/2023 in #help
✅ Changing the individual font of items in a Combo Box - C# Windows Forms
oh sure I'll try that
24 replies
CC#
Created by PotatOBiTz on 7/12/2023 in #help
✅ Changing the individual font of items in a Combo Box - C# Windows Forms
24 replies
CC#
Created by PotatOBiTz on 7/12/2023 in #help
✅ Changing the individual font of items in a Combo Box - C# Windows Forms
this is the current state. As you can see in the combo box it displays [Font Family: Name = <Font Name>] instead of just the font name
24 replies
CC#
Created by PotatOBiTz on 7/12/2023 in #help
✅ Changing the individual font of items in a Combo Box - C# Windows Forms
hmm, I want the combo box to display "Calibri" for example instead of "[Font Family: Name=Calibri]" when I select it from the list of items. But I don't know what's causing it to be like that, and which to change
24 replies
CC#
Created by PotatOBiTz on 7/12/2023 in #help
✅ Changing the individual font of items in a Combo Box - C# Windows Forms
perhaps I did, this came from the code snippet I found from stack overflow btw, I don't completely understand what is happening aside from that DataSource is a collection of objects and that DrawItem changes how a combo box/listbox is drawn. The rest I have a vague understanding
24 replies
CC#
Created by PotatOBiTz on 7/12/2023 in #help
✅ Changing the individual font of items in a Combo Box - C# Windows Forms
yep, I've enabled this to OwnerDrawFixed
24 replies
CC#
Created by PotatOBiTz on 7/12/2023 in #help
✅ Changing the individual font of items in a Combo Box - C# Windows Forms
I tried to declare variables to hold the System.Drawing.FontFamily.Families, then put it inside cboFont.DataSource (something like a cboFont.DataSource = font.Name) so I can put a .Name on the variable, but ig that doesn't work. I've never worked with DrawItem events nor .DataSource, this is perhaps my first time trying to understand these
24 replies
CC#
Created by PotatOBiTz on 7/12/2023 in #help
✅ Changing the individual font of items in a Combo Box - C# Windows Forms
24 replies
CC#
Created by PotatOBiTz on 7/12/2023 in #help
✅ Changing the individual font of items in a Combo Box - C# Windows Forms
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace g7ccs
{
public partial class frmFont : Form
{
public frmFont()
{
InitializeComponent();
cboFont.DrawItem += cboFont_DrawItem;
/*foreach(FontFamily fontfamily in FontFamily.Families)
{
cboFont.Items.Add(fontfamily.Name);
}
*/
cboFont.DataSource = System.Drawing.FontFamily.Families.ToList();
}

private void cboFont_DrawItem(object sender, DrawItemEventArgs e)
{
var comboBox = (ComboBox)sender;
var fontFamily = (FontFamily)comboBox.Items[e.Index];
var font = new Font(fontFamily, comboBox.Font.SizeInPoints);

e.DrawBackground();
e.Graphics.DrawString (font.Name, font, Brushes.Black, e.Bounds.X, e.Bounds.Y);
}

private void cboFont_SelectedIndexChanged(object sender, EventArgs e)
{
string sFontName = cboFont.SelectedItem.ToString();
Font selectedFont = new Font(sFontName, lblSample.Font.Size, lblSample.Font.Style);
lblSample.Font = selectedFont;
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace g7ccs
{
public partial class frmFont : Form
{
public frmFont()
{
InitializeComponent();
cboFont.DrawItem += cboFont_DrawItem;
/*foreach(FontFamily fontfamily in FontFamily.Families)
{
cboFont.Items.Add(fontfamily.Name);
}
*/
cboFont.DataSource = System.Drawing.FontFamily.Families.ToList();
}

private void cboFont_DrawItem(object sender, DrawItemEventArgs e)
{
var comboBox = (ComboBox)sender;
var fontFamily = (FontFamily)comboBox.Items[e.Index];
var font = new Font(fontFamily, comboBox.Font.SizeInPoints);

e.DrawBackground();
e.Graphics.DrawString (font.Name, font, Brushes.Black, e.Bounds.X, e.Bounds.Y);
}

private void cboFont_SelectedIndexChanged(object sender, EventArgs e)
{
string sFontName = cboFont.SelectedItem.ToString();
Font selectedFont = new Font(sFontName, lblSample.Font.Size, lblSample.Font.Style);
lblSample.Font = selectedFont;
}
24 replies
CC#
Created by PotatOBiTz on 7/12/2023 in #help
✅ Changing the individual font of items in a Combo Box - C# Windows Forms
ah sure hang on
24 replies