How to show a hyperlink inside the description field of an AboutBox - c#

I want to place a link inside the description field of my applications about box which will direct users to a wiki page for more help. I can't figure out how to make the address appear as a link.
I set the description through the assembly information properties.

There's a WinForms control you can use to achieve what you want: the LinkLabel.
Simply add one to your AboutBox layout and double click it. A handler to its LinkClicked event will be created, and there you can then use Process.Start to open your website's URL.
public AboutBox1()
{
InitializeComponent();
this.Text = String.Format("About {0}", AssemblyTitle);
this.labelProductName.Text = AssemblyProduct;
this.labelVersion.Text = String.Format("Version {0}", AssemblyVersion);
this.labelCopyright.Text = AssemblyCopyright;
this.labelCompanyName.Text = AssemblyCompany;
this.textBoxDescription.Text = AssemblyDescription;
this.Link.Text = "Visit our website!";
this.Link.Tag = WpfApplication2.Properties.Resources.website;
}
private void Link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start((sender as LinkLabel).Tag.ToString());
}
In my case, I've saved the URL as an application resource. And I've showed it separately from the Assembly Description.
If you want the link to appear inside the Assembly Description, it's quite a bit more complicated...

Related

How do I navigate to another page from another c# class

I have a main page which has a play, options and exit button, both the play and exit button work as I followed a tutorial on it however for the options button I do not know how to navigate it. What I am planning to do is to create another class called optionsMenu.cs and have like a credits screen or a how to play guide on it.
These are the codes that I have for my options button.
var optionsGameButton = new Button(buttonTexture, buttonFont)
{
Position = new Vector2(300, 250),
Text = "Options",
};
optionsGameButton.Click += OptionsGameButton_Click;
_components = new List<Component>()
{
titleGameButton,
playGameButton,
optionsGameButton,
exitGameButton,
};
Finally I know I have to write a code in this area to be able to get the options button working but I don't know which kind of code to put.
private void OptionsGameButton_Click(object sender, EventArgs e)
{
Console.WriteLine("Credits");
}
If you're set on using click events, then you'll need to create a new instance of your options page and set it as the content of your control object within OptionsGameButton_Click. On the options page you'll need to set the xmlns to your optionsMenu.cs file.
I think you could also set the content of your control object by passing it as a parameter within the method itself, but I've only done this using the ICommand interface.

Access Gtk# (GtkSharp) Label child of a Button

I have a C# project in MonoDevelop.
Long story short is I found I wasnt able to apply styling/pango/markup/images if I used the Button with Label in the Stetic GUI.
The documentation i read and some code I see said to make a Label or Image and pack it into the Button.
I did that for a Label and it worked successfully to style it.
A sample of the object Build method:
private void Build()
{
box = new HBox(false, 0);
box.SetSizeRequest(40, 40);
box.BorderWidth = 2;
button = new Button();
button.Clicked += cyclepoint;
lblpoints = new Label();
lblpoints.Text = "200";
lblpoints.ModifyFg(Gtk.StateType.Normal, new Gdk.Color(237, 52, 112));
button.Add(lblpoints);
button.ShowAll();
box.Add(this.button);
box.ShowAll();
this.Add(box);
}
So that is fine. Now I'm trying to attach the Signal so that whenever the Button is click it would change the Label Text for the particularly clicked button (as there will be multiple of the form.
Code I have for the signal:
private void cyclepoint(object sender, EventArgs args)
{
Console.WriteLine("Button Pressed!");
Console.WriteLine((Label)(((Button)sender).Child).Text);
}
Actual Output When I build the GUI and click the button
Button Pressed!
GtkLabel
Yet when I try to below to do a change the MonoDevelop IDe wont compile with error:
Error CS1061: 'Widget' does not contain a definition for 'Text' and no accessible extension method 'Text' accepting a first argument of type 'Widget' could be found (are you missing a using directive or an assembly reference?) (CS1061) (shump)
So I dont seem to be able to access the Text property of the Gtk.Label to change it's display Text. What is the correct way to go about doing this?
So in my regard. I dont believe I can access the "Child" element of the Gtk.Button object.
However, I've since discovered that I can access and edit the GTK.Label.Text property of the child Gtk.Label object directly from within the class. This will automatically update the Label with no necessary calls to Show() functions so will reflect the update immediately to boot! Furthermore, it also keeps the pango styling properties I had applied.
The end goal was to have a stylized countdown type of Button object that reduces the number as clicked and goal was accomplished.
private void cyclepoint(object sender, EventArgs args)
{
// Points is a different array that holds the increments of values
if (this.lblpoints.Text == points[10])
{
lblpoints.Text = points[0];
}
else
{
int nextval;
nextval = (Array.IndexOf(points, this.lblpoints.Text) + 1);
this.lblpoints.Text = points[nextval];
}
}

How to add a ListBox programmatically in a Form

I started out C# very recently and sorry if this question sounds dumb.
How do I add a Listbox in a Form that pops out from a Button click?
Note: The Form isn't the one that's added from the Solution Explorer whereby I can just drag a Listbox from the Toolbox to my Form.
So what I want is to create a ListBox in my file drawer1Form where I can add additional items. Thanks for the help in advance!:)
private void drawer1button_Click(object sender, EventArgs e) // Drawer 1 Button
{
drawer1Form df1 = new drawer1Form();
df1.StartPosition = FormStartPosition.CenterScreen;
df1.Show();
}
public partial class drawer1Form : Form // Creates drawer1Form
{
public drawer1Form()
{
Text = "Drawer 1 ";
}
}
Pretty much the same way as you'd do with any other object.
In the class of your form add a
private ListBox myAwesomeListBox;
Then in the button event handler add something like this:
myAwesomeListBox = new ListBox();
myAwesomeListBox.SuspendLayout();
// set all the properties that you want
myAwesomeListBox.Name = "myAwesomeListBox";
myAwesomeListBox.Location = new Point(...); // place it somewhere
myAwesomeListBox.Size = new Size(...); // give it a size
// etc...
df1.Controls.Add(myAwesomeListBox);
myAwesomeListBox.ResumeLayout();
This should be it.
I highly advise you to do it through the designer first though, and then take a look at the generated code in the form's .Designer.cs file, you'll have a very good understanding after reading through that.

ObjectListView editing doesn't work

I'm trying to create a simple listbox with ObjectListView (WinForm, C#). The goal is to have a single value (a double) and a check box.
I want to be able to edit the double value by Single Click, so here are the relevant lines of code from my MyWindow.Designer.cs file (i've left out the default values for efficiency):
this.olvDepths = new BrightIdeasSoftware.ObjectListView();
this.olvColumn1 = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn()));
...
this.olvDepths.CellEditActivation = BrightIdeasSoftware.ObjectListView.CellEditActivateMode.SingleClick;
this.olvDepths.CheckBoxes = true;
this.olvDepths.CheckedAspectName = "IsDefault";
this.olvDepths.FullRowSelect = true;
//
// olvColumn1
//
this.olvColumn1.AspectName = "Depth";
this.olvColumn1.Text = "";
this.olvColumn1.IsEditable = true;
I then create a list of my class (ShieldingEntry) and use the olvDepths.SetObjects() with the list. My ShieldingEntry class looks like this:
public class ShieldingEntry
{
public double Depth { get; set; }
public bool IsDefault { get; set; }
}
However, when I click the field, it doesn't go into edit mode. I've also tried the DoubleClick, SingleClickAlways, and F2Only modes and they don't work either.
The Checkbox works fine.
************** I have additional information *********************
I've pulled and build the ObjectListView source, so I could step through it.
I put a breakpoint in the OLV StartCellEdit method and it gets called and appears to setup and select the control appropriately. It just never appears...
As I noted in the comments on the answer below, I've got this control on a tabbed dialog, and if I switch to another tab, then back, the control works fine.
What am I missing?
I've used ObjectListView before, and here is what I had to do:
Handle the CellEditStarting event. This event is raised when the cell goes into edit mode. Since OLV doesn't really have built-in editors, you have to make your own. Then handle the CellEditFinishing event to validate the data before putting it back into your model.
So first, handling the CellEditStarting event:
private void objlv_CellEditStarting(object sender, CellEditEventArgs e)
{
//e.Column.AspectName gives the model column name of the editing column
if (e.Column.AspectName == "DoubleValue")
{
NumericUpDown nud = new NumericUpDown();
nud.MinValue = 0.0;
nud.MaxValue = 1000.0;
nud.Value = (double)e.Value;
e.Control = nud;
}
}
This creates your editing control. If you want to make sure the size is right, you can set the size of the control (in this case a NumericUpDown) to the cell bounds using e.CellBounds from the event object.
This will show the editor when you click in the cell. Then you can handle the editor finished event to validate the data:
private void objlv_CellEditFinishing(object sender, CellEditEventArgs e)
{
if (e.Column.AspectName == "DoubleValue")
{
//Here you can verify data, if the data is wrong, call
if ((double)e.NewValue > 10000.0)
e.Cancel = true;
}
}
I don't think handling it is required, but its good practice to validate data from the user.
The editing control in the CellEditStarting event can be any control, even a user defined one. I've used a lot of user defined controls (like textboxes with browse buttons) in the cell editor.
[Edit]
I uploaded an example here dropbox link that seems to work. Might not be in the exact view as needed, but seems to do the job.
For anyone else with this problem. I had it specifically when trying to edit a 'null' value in a decimal? on the OLV on a tab page. Solution for me was to set UseCustomSelectionColors to 'False'. I didn't look elsewhere to see if it was reported as a bug. Seems like a bug.

How to change icon and text to a ApplicationBarIconButton?

I want to make my click event change an ApplicationBarIconButton. My ApplicationBarIconButton looks like this:
<shell:ApplicationBarIconButton x:Name="driveAction" Click="drive_click" IconUri="/img/car.png" Text="kör" />
I want the IconUri to change from /img/car.png to ex. /img/car-stop.png and the text value from kör to passagera. I tried the function below, but it only causes my app to shut down.
private void drive_click(object sender, EventArgs e)
{
this.driveAction.Text = "passagera";
this.driveAction.Source = "/img/car-stop.png";
}
What is wrong? Why doesn't this work?
The default ApplicationBar requires you to access the buttons through the ApplicationBar object. To accomplish this you must know the index of the button that you want to change
private const int DriveButtonIndex = 0;
private void drive_click(object sender, EventArgs e)
{
var button = (ApplicationBarIconButton)ApplicationBar.Buttons[DriveButtonIndex];
button.IconUri = new Uri("/img/car-stop.png", UriKind.Relative);
button.Text = "passagera";
}
There are a few custom ApplicationBars that allow you to name your buttons. But I've found that the above solution always works for me.
Get it directly from the application bar list -
ApplicationBar.Buttons[0].Text = "passagera";
ApplicationBar.Buttons[0].Source = "/img/car-stop.png";
You could also query the list of buttons for a specific icon as a more tenable long-term solution, but if you only have one button and that's not going to change, this works.
Because the ApplicationBarIconButton is actually a native control and not a true XAML object you cannot refer to it by name.
You can refer to it by index if create in XAML. Alternatively you could create it in code and then you can maintain a named reference you can use.

Categories

Resources