Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
RichTextbox with context menu for setting Color and Font in .Net windows application
WhatsApp
Shinuraj
14y
26.7k
0
0
100
Article
Steps:
Add a RichTextBox to the Form
Add Contextmenu and set two items as a)Add Color , b)Set Font
Set this as the contextmenu for the RichTextbox(take the property and directly set )
Add ColorDialog and fontDialog to the form
Hook the event contextMenuStrip1_ItemClicked and use the "SelectionFont" and "SelectionColor" property of RichTextbox as shown in the below code to set the color and font
private
void
contextMenuStrip1_ItemClicked(
object
sender, ToolStripItemClickedEventArgs e)
{
if
(e.ClickedItem.Text ==
" Add Color "
)
{
DialogResult color = colorDialog1.ShowDialog();
// See if user pressed ok.
if
(color == DialogResult.OK)
{
// Set Color to the selected text
this
.richTextBox1.SelectionColor = colorDialog1.Color;
}
}
if
(e.ClickedItem.Text ==
" Set Font "
)
{
DialogResult font = fontDialog1.ShowDialog();
if
(font == DialogResult.OK)
{
// Set selection font to the fontDialog1.Font
this
.richTextBox1.SelectionFont = fontDialog1.Font;
}
}
}
.net
.Net windows application
context menu
RichTextbox
windows application
olorDialog
Up Next
Ebook Download
View all
GitHub Copilot - Coding with Copilot
Read by 2.7k people
Download Now!
Learn
View all
Membership not found