MessageBox.Show() fonts - c#

Is there a way I can change the font types in a MessageBox.Show() to get bigger size, bold, italic styles?

You can always make your own MessageBox creating a new Windows.Forms class:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MessageBoxFont
{
public partial class Message : Form
{
public Message(String text)
{
InitializeComponent();
tbxMessage.Text = text;
btnOK.Focus();
}
private void btnOK_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Then you can control the properties (like the font, size, color and the like) shown under the solution explorer. You initialize this form like this:
private void OpenMessageBox()
{
String text = "This is a sample error message";
Message message = new Message(text);
message.Show();
}
Its a work-around, however, easier to implement :)

I believe that those fonts are controlled by the operating system.
You could (however) make a custom dialog and put anything you want in there including custom fonts.
Here is the MSDN resource for custom dialogs.
http://msdn.microsoft.com/en-us/library/2chz8edb(VS.90).aspx

Have you thought of something like a customized message box (www.html-messagebox.com)?
For more customization such as building an irregular shaped message box (Homer Simpson's head), you are better off creating your own MessageBox-like implementation for your project.

Check this http://www.windowsdevelop.com/windows-forms-general/change-font-size-for-messageboxshow-dialogs-62092.shtml

Related

Creating a round button for my WPF app in visual studio 2013. Problem here is onPaint() Method generate error asking me to enter some valid parameters

Creating a round button for my WPF app in visual studio 2013. The problem here is onPaint() Method generates error asking me to enter some valid parameters.
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace CurrencyTeller
{
class CircularButton:Button
{
protected override void OnPaint (PaintEventArgs pevent)
{
GraphicsPath grpath = new GraphicsPath();
grpath.AddEllipse(0,0,ClientSize.Width,ClientSize.Height);
this.Region = new System.Drawing.Region(grpath);
base.OnPaint(pevent);
}
}
}
Error 3 Argument 1: cannot convert from 'CurrencyTeller.PaintEventArgs' to 'System.Windows.Forms.PaintEventArgs'
From what I can see, youre creating a Forms control, not a WPF control. Create a new "WPF User Control" in your Project and port your button to the template. Beware that Windows.Forms controls dont work in a WPF enviroment.
Best you look at some WPF Control tutorial.

"Recently Visited Sites" Application in C#

Let me clear the air first: yes, this is classwork. No, I don't just want the answer. I am just really stuck and looking for some assistance.
I'll be as specific as I can. I think the best way I can do that is to post the prompt the book gives:
Create a project named RecentlyVisitedSites that contains a Form with a list of three LinkLabels that link to any three Web sites you choose. When a user clicks a LinkLabel, link to that site. When a user's mouse hovers over a LinkLabel, display a brief message that explains the site's purpose. After a user clicks a link, move the most recently selected link to the top of the list, and move the other two links down, making sure to retain the correct explanation with each link.
My main problem with this is that I can't find a good way to make a "list" of the LinkLabels that both allows me to use LinkLabels in the first place and lets me rearrange items in a list-fashion. Here is my best go at it:
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 RecentlyVisitedSites
{
public partial class Form1 : Form
{
LinkLabel[] links = new LinkLabel[3];
public Form1()
{
InitializeComponent();
/*LinkLabel[] links = new LinkLabel[3];
links[0] = new LinkLabel();
links[0].Text = "google.com";
links[0].Location = new System.Drawing.Point(100, 25);
links[0].Links.Add(0, 0, "www.google.com");
this.Controls.Add(links[0]);*/
LinkLabel[] links = new LinkLabel[3];
links[0] = googleLabel;
links[1] = facebookLabel;
linksPanel.Controls.Add(links[0]);
linksPanel.Controls.Add(links[1]);
}
private void googleLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("IExplore", "http://www.google.com");
links[0] = googleLabel;
linksPanel.Controls.Remove(links[0]);
linksPanel.Controls.Add(links[0]);
}
private void facebookLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("IExplore", "http://www.facebook.com");
links[0] = facebookLabel;
linksPanel.Controls.Remove(links[0]);
linksPanel.Controls.Add(links[0]);
}
}
}
And I always get stuck either because the links won't show up, or I can't use them the way the prompt seems to want, or some other thing. The commented-out code is something else I tried using after asking my teacher, but I didn't get much out of our conversation and it didn't work either.
What should I be doing to get these links to display on page, in a list, where I can have them be clickable, open the stated web page in a browser, and be able to rearrange them the way the prompt asks?
Again, I'm not just asking to be given an answer, I have just hit a wall and I'm frustrated because I can't seem to find a decent explanation to help me understand what I actually need to be doing. Any help would be appreciated.
Use this format for each LinkLabel on Form1:
LinkLabel.LinkVisited = true;
System.Diagnostics.Process.Start("IExplore, http://www.Facebook.com");

VSTO Word - adding a table row on button click from task pane

I have a VSTO project where a click of a button on the ribbon, opens a new Word doc with a specific template, and opens it with a custom task pane. On that pane is a button, which when clicked, i want to add a row to a table which exists in the doc template.
Currently i'm just getting a 'command failed' exception at run time when the button on the task pane is clicked. Here is the whole class. As you can see i've tried two ways to do it, both fail:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using word = Microsoft.Office.Interop.Word;
namespace TestWordAddin2010
{
public partial class NewDescDMtaskPane : UserControl
{
public NewDescDMtaskPane()
{
InitializeComponent();
}
private void addSpare_Click(object sender, EventArgs e)
{
Globals.ThisAddIn.Application.ActiveDocument.Tables[1].Rows.Add(Globals.ThisAddIn.Application.ActiveDocument.Tables[1].Rows[1]); //this doesn't work
//word.Table wordTable = Globals.ThisAddIn.Application.ActiveDocument.Tables[1];
//wordTable.Rows.Add(wordTable.Rows[1]); //neither does this work
}
}
}
Any help appreciated.
Most likely your first table contains merged cells. Then you won't be able to access individual rows in the Rows collection.
As a workaround you could use the Selection object as follows:
ActiveDocument.Tables(1).Range.Select();
Application.Selection.Collapse();
Application.Selection.InsertRowsAbove();

Invalidate UserControl Error in C#

I created an UserControl and everything works great except for the properties. The problem is I lost all the Design Property in my UserControl.. to be more clear, i made a screenshot.
This is my UserControl
..and a ToolStrip sample
this is my sample code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using System.ComponentModel.Design;
namespace _Sample__User_Control
{
[Designer("Sytem.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(IDesigner))]
public partial class ClientsCollectionListBox : UserControl
{
public ClientsCollectionListBox()
{
InitializeComponent();
}
[Browsable(true)]
[DefaultValue("Hello")]
public string MyString { get; set; }
}
}
my User Control doesn't have the Design Property. Upon dragging the User Control to my form, there's still the Design Property but upon running or adding another instance to this control, i lost the display. Any help for this problem would be appreciated. Do i need to Invalidate on load?
SOLUTION:
Spelling error.. sorry.. please close this thread..
[Designer("Sytem.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(IDesigner))]
[Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(IDesigner))]

HTML to Image: The Confusion Begins

Currently I load an HTML string into a webBrowser control's contents and tell the user to print-screen it.
I'd like to somehow either grab the webBrowser contents as an image, or somehow render this HTML to an image file that can be saved. Are there any free libraries to do this?
I have been curious as to how this is accomplished myself. I have not tried to do this, but here is a link to a CodeProject article that seems to describe the process quite well:
HTML to Image in C#
I use a program called Webshot and I absolutely love it. It has a freeware version with upgrade available. It even has a callable command line interface which can be used in an automated fashion.
Link here.
Well, there's bound to be a better solution than this, but I'm pretty sure it's better than your solution (I haven't checked out the other answers), so...
I have a working C# program that saves a bitmap image of a control. Currently, the control is a textbox, but you could easily make it a web browser control. The entire program is below. The form has a button, button1, and a textbox, textBox1.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap bm = new Bitmap(textBox1.Width,textBox1.Height);
textBox1.DrawToBitmap(bm,new Rectangle(0,0,bm.Width,bm.Height));
bm.Save("image.bmp");
}
}
}

Categories