can someone explain how can I fix it...
I use Metro Framework downloaded from GitHub and when I use two metro tile I get form like on image bellow.
But I want when click on "Theme" or "Color" to change like default. You can see on top not change color and window not change to dark theme but only metro text box, metro label but metro panel it's OK.
private void metroTileSwitch_Click(object sender, EventArgs e)
{
var m = new Random();
int next = m.Next(0, 13);
metroStyleManager.Style = (MetroColorStyle)next;
}
private void metroTile1_Click(object sender, EventArgs e)
{
metroStyleManager.Theme = metroStyleManager.Theme == MetroThemeStyle.Light ? MetroThemeStyle.Dark : MetroThemeStyle.Light;
}
Thank you for help.
Be sure of that :
step 1- items that doesn't change theme , theme property is set to Default example:
this.Theme = MetroThemeStyle.Default;
step 2- set owner of metroStyleManager to this form :
metroStyleManager1.Owner = this;
step 3- if problem still you need to connect each item to metroStyleManager example :
this.StyleManager = metroStyleManager1;
metroTextBox1.StyleManager = metroStyleManager1;
//etc...
Related
I have a label that is setup to look like a UK Standard Number Plate.
The font is set to Charles Wright.
I want to be able to toggle the background image of this label with the use of a button, but I want this button to be able to identify what image is currently being used so that it can change the image accordingly.
The images are stored in the 'Properties.Resources' as 'plainFrontNumberPlate.bmp' and 'borderedFrontNumberPlate.bmp'.
I have tried:
if(this.label1.Image == Resources.plainFrontNumberPlate)
{
this.label1.Image = Resources.borderedFrontNumberPlate;
}
else
{
this.label1.Image = Resources.plainFrontNumberPlate;
}
But when I try to test this. The first click changes the image to 'borderedFrontNumberPlate.bmp but not back to 'plainFrontNumberPlate.bmp when I click a twice.
use this code
public Form1()
{
InitializeComponent();
this.label1.Image.Tag = "plainFrontNumberPlate";
}
private void btnChangeImage_Click(object sender, EventArgs e)
{
switch (this.label1.Image.Tag.ToString())
{
case "plainFrontNumberPlate":
object borderedFrontNumberPlate = Resources.ResourceManager.GetObject("borderedFrontNumberPlate");
this.label1.Image = (Image)borderedFrontNumberPlate;
this.label1.Image.Tag = "borderedFrontNumberPlate";
break;
case "borderedFrontNumberPlate":
object plainFrontNumberPlate = Resources.ResourceManager.GetObject("plainFrontNumberPlate");
this.label1.Image = (Image)plainFrontNumberPlate;
this.label1.Image.Tag = "plainFrontNumberPlate";
break;
}
}
Thank you both 'Jimi' & 'Meysam Asadi' both your answers & comments worked. I preferred to use 'Meysam Asadi' code example as it was clearly laid out and easier for me to understand.
The combination of your help has solved my issue. Thank you
Finally managed to get the Colorpickers down and sorted and they currently work on a OnNavigateTo basis.
When I pick a color from color picker I would like to to be applied eith instantly to the Foreground of my NavigationViewItems OR apply once i click the button within the settings page called TextColourApply_Click.
The mentioned color picker is on the settingspage currently and the NavigationViewItems are on the MainPage.
I was looking at doing a UI refresh but this doesnt work with UWP as far as i can tell. As a work around, i was looking at doing a current Frame navigate but this doesnt work
I have the following that allows the selected colour to apply when navigating back to the "MainPage":
protected override void OnNavigatedTo(NavigationEventArgs e)
{
SolidColorBrush DefaultTextColour = Application.Current.Resources["DefaultTextColour"] as SolidColorBrush;
if (ColourSelections.TextColour != null)
{
DefaultTextColour = ColourSelections.TextColour;
}
foreach (var item in NavView.MenuItems.OfType<NavigationViewItem>())
{
item.Foreground = DefaultTextColour;
}
}
Any ideas on how to impliment this would be appreciated. Thank you
if your desired behaviour is following :
When I pick a color from color picker it should be applied instantly to the Foreground of my NavigationViewItems and color picker is on settings page.
In that case you do not need OnNavigatedTo on your MainPage and you do not need the Apply as well, So remove your OnNavigatedTo method also remove the Apply button from your settings page and then Just do the following:
Create a public static property within your ShellPage (the page where your NavigationView exists) that will expose your NavigationView, and make sure to initialize it within the constructor of your ShellPage.
public static NavigationView MyNavView;
public ShellPage()
{
this.InitializeComponent();
MyNavView = NavView; //here you assign your navigation view to the public static property so you can access it outside this shell page as well.
}
Now within the colorChanged event (in your settings page) of your color picker assign the color to the foreground of your navigationmenuItems.
private void TextColourPicker_ColorChanged(ColorPicker sender, ColorChangedEventArgs args)
{
SolidColorBrush DefaultTextColour = new SolidColorBrush(TextColourPicker.Color);
foreach (var item in ShellPage.MyNavView.MenuItems.OfType<NavigationViewItem>())
{
item.Foreground = DefaultTextColour;
}
}
and just to make sure that whenever your app is loaded for the first time you get the default color set in your resources, assign a Loaded event to your NavigationView and set the default color in there.
add the loaded event in xaml like this :
<NavigationView x:Name="NavView" Loaded="NavView_Loaded">
and the event in your backend will be :
private void NavView_Loaded(object sender, object args)
{
SolidColorBrush DefaultTextColour = Application.Current.Resources["DefaultTextColour"] as SolidColorBrush;
foreach (var item in NavView.MenuItems.OfType<NavigationViewItem>())
{
item.Foreground = DefaultTextColour;
}
}
Please note that now you do not even need the public static class you were using before for saving the colors, so you can remove that class as well.
quick question,
(im using visual studio 2012/ windows phone 8 application)
how can i get the properties of a textblock on its tap event?
i have the tap event :
void item_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
var control = (sender as TextBlock);
MessageBox.Show(control.Text + ", was tapped!", "Happyness", MessageBoxButton.OK);
}
i get most of the properties, but the ones i want i dont get, i would like to see what is that textblock's "Grid.Row" property? is that possible?
ah i found it! hopes this help other people aswell,
all i did was :
var myrow = control.GetValue(Grid.RowProperty);
and the result was = 1;
have a good one!
I know that richtextboxes can detect links (like http://www.yahoo.com) but is there a way for me to add links to it that looks like text but its a link? Like where you can choose the label of the link? For example instead of it appearing as http://www.yahoo.com it appears as Click here to go to yahoo
edit: forgot, im using windows forms
edit: is there something thats better to use (as in easier to format)?
Of course it is possible by invoking some WIN32 functionality into your control, but if you are looking for some standard ways, check this post out:
Create hyperlink in TextBox control
There are some discussions about different ways of integration.
greetings
Update 1:
The best thing is to follow this method:
http://msdn.microsoft.com/en-us/library/f591a55w.aspx
because the RichText box controls provides some functionality to "DetectUrls". Then you can handle the clicked links very easy:
this.richTextBox1.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.richTextBox1_LinkClicked);
and you can simple create your own RichTextBox contorl by extending the base class - there you can override the methods you need, for example the DetectUrls.
Here you can find an example of adding a link in rich Textbox by linkLabel:
LinkLabel link = new LinkLabel();
link.Text = "something";
link.LinkClicked += new LinkLabelLinkClickedEventHandler(this.link_LinkClicked);
LinkLabel.Link data = new LinkLabel.Link();
data.LinkData = #"C:\";
link.Links.Add(data);
link.AutoSize = true;
link.Location =
this.richTextBox1.GetPositionFromCharIndex(this.richTextBox1.TextLength);
this.richTextBox1.Controls.Add(link);
this.richTextBox1.AppendText(link.Text + " ");
this.richTextBox1.SelectionStart = this.richTextBox1.TextLength;
And here is the handler:
private void link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
I found a way which may not be the most elegant, but it's just a few lines of code and does the job. Namely, the idea is to simulate hyperlink appearance by means of font changes, and simulate hyperlink behavior by detecting what the mouse pointer is on.
The code:
public partial class Form1 : Form
{
private Cursor defaultRichTextBoxCursor = Cursors.Default;
private const string HOT_TEXT = "click here";
private bool mouseOnHotText = false;
// ... Lines skipped (constructor, etc.)
private void Form1_Load(object sender, EventArgs e)
{
// save the right cursor for later
this.defaultRichTextBoxCursor = richTextBox1.Cursor;
// Output some sample text, some of which contains
// the trigger string (HOT_TEXT)
richTextBox1.SelectionFont = new Font("Calibri", 11, FontStyle.Underline);
richTextBox1.SelectionColor = Color.Blue;
// output "click here" with blue underlined font
richTextBox1.SelectedText = HOT_TEXT + "\n";
richTextBox1.SelectionFont = new Font("Calibri", 11, FontStyle.Regular);
richTextBox1.SelectionColor = Color.Black;
richTextBox1.SelectedText = "Some regular text";
}
private void richTextBox1_MouseMove(object sender, MouseEventArgs e)
{
int mousePointerCharIndex = richTextBox1.GetCharIndexFromPosition(e.Location);
int mousePointerLine = richTextBox1.GetLineFromCharIndex(mousePointerCharIndex);
int firstCharIndexInMousePointerLine = richTextBox1.GetFirstCharIndexFromLine(mousePointerLine);
int firstCharIndexInNextLine = richTextBox1.GetFirstCharIndexFromLine(mousePointerLine + 1);
if (firstCharIndexInNextLine < 0)
{
firstCharIndexInNextLine = richTextBox1.Text.Length;
}
// See where the hyperlink starts, as long as it's on the same line
// over which the mouse is
int hotTextStartIndex = richTextBox1.Find(
HOT_TEXT, firstCharIndexInMousePointerLine, firstCharIndexInNextLine, RichTextBoxFinds.NoHighlight);
if (hotTextStartIndex >= 0 &&
mousePointerCharIndex >= hotTextStartIndex && mousePointerCharIndex < hotTextStartIndex + HOT_TEXT.Length)
{
// Simulate hyperlink behavior
richTextBox1.Cursor = Cursors.Hand;
mouseOnHotText = true;
}
else
{
richTextBox1.Cursor = defaultRichTextBoxCursor;
mouseOnHotText = false;
}
toolStripStatusLabel1.Text = mousePointerCharIndex.ToString();
}
private void richTextBox1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && mouseOnHotText)
{
// Insert your own URL here, to navigate to when "hot text" is clicked
Process.Start("http://www.google.com");
}
}
}
To improve on the code, one could create an elegant way to map multiple "hot text" strings to their own linked URLs (a Dictionary<K, V> maybe). An additional improvement would be to subclass RichTextBox to encapsulate the functionality that's in the code above.
Many moons later there is a solution for .NET (Core), as of at least .NET 6.0 (possibly earlier) - for .NET Framework (whose latest and last version is 4.8) you'll still need one of the other solutions here:
The .Rtf property now recognizes RTF-format hyperlinks; e.g., the following renders as:
This is a true RTF hyperlink: Example Link
this.richTextBox1.Rtf = #"{\rtf1 This is a true RTF hyperlink:\line {\field{\*\fldinst HYPERLINK ""https://example.org""}{\fldrslt Example Link}}} }";
The standard RichTextBox control (assuming you are using Windows Forms) exposes a rather limited set of features, so unfortunately you will need to do some Win32 interop to achieve that (along the lines of SendMessage(), CFM_LINK, EM_SETCHARFORMAT etc.).
You can find more information on how to do that in this answer here on SO.
I am working on a project in c# using windows forms.
me and the group I am in want to make it so that when the user hovers their mouse over an image, in our case a card, that a larger image of that card appears next to the mouse arrow, much in the same way a tool tip would work.
I don't think you can use a tool tip to do this i have tried looking everywhere,
any advice or examples would be great thank you very much
You may want to look at this Code Project Article
It shows you how to create an OwnerDrawn ToolTip with an Image.
Thanks for the responses I got everything figured out.
What I wanted to do was that when I moused over a certain area a different image for that area would popup in the same way that a tool tip did. So after some research I figured out how to create my own tool tip class.
here's an example.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
CustomToolTip tip = new CustomToolTip();
tip.SetToolTip(button1, "text");
tip.SetToolTip(button2, "writing");
button1.Tag = Properties.Resources.pelican; // pull image from the resources file
button2.Tag = Properties.Resources.pelican2;
}
}
class CustomToolTip : ToolTip
{
public CustomToolTip()
{
this.OwnerDraw = true;
this.Popup += new PopupEventHandler(this.OnPopup);
this.Draw +=new DrawToolTipEventHandler(this.OnDraw);
}
private void OnPopup(object sender, PopupEventArgs e) // use this event to set the size of the tool tip
{
e.ToolTipSize = new Size(600, 1000);
}
private void OnDraw(object sender, DrawToolTipEventArgs e) // use this to customzie the tool tip
{
Graphics g = e.Graphics;
// to set the tag for each button or object
Control parent = e.AssociatedControl;
Image pelican = parent.Tag as Image;
//create your own custom brush to fill the background with the image
TextureBrush b = new TextureBrush(new Bitmap(pelican));// get the image from Tag
g.FillRectangle(b, e.Bounds);
b.Dispose();
}
}
}
A simple way to do is to hide/show a picture box at specified location. Another method is to load & draw (paint) an image using GDI API.