C# Button Shape issue - c#

I recently tried to follow this tutorial here but I don't really understand how it works. My problem is that I don't see any button like the in the image or anything like that, there is no button on my form.
Also here is the full source code from the tutorial. I would like to know how to add the circle with the buttons on my form.
Thank you

From your comment it seems that you have not added this Button to your Form.
In your Form code behind in constructor add:
public Form1()
{
InitializeComponent();
var btn = new simonButton(); //create button
this.Controls.Add(btn); //add it to form, it will be positioned in location (0,0) top-left corner
}

If you've added the new button class and successfully compiled, then you should have the new button called "simonButton" appearing at the TOP of your ToolBox so you can add them to your form like any other control. Change the ForeColor() property through the IDE to change the color of the button.

Related

Switching pages instead of windows

So currently I'm switching to a whole new window when i use my page switch button. But what I actually would like it to do is in the same window switch to another page. I have searched the internet and found some page switch with a button but when I set it up and click the button half the screen just goes white and the other half stays. I hope someone can help me with some click event or something that can do what I need. Hope you understand what I mean.
My current code for switching windows on a button click is this:
Newpage objNewpage = new Newpage();
this.Visibility = Visibility.Hidden;
objNewpage.Show();
Put instead what I would like is to open a new page on the same window.
//Ossie

C#- Add Image and text to Dialog Form that appears on clicking on a submenu of a Toolstripmenuitem

I have created a ToolStripMenuItem called "About". Underneath "About", I have a submenu called "About MatchingGame". Upon clicking on "About MatchingGame", I want it to display a dialog box. In that box, I want to be able to show an image and some text (one field on top of another).
So far, I have this code for the about menu:
private void aboutMatchingGameToolStripMenuItem_Click(object sender, EventArgs e)
{
Form dlg1 = new Form();
dlg1.ShowDialog();
}
This gives me the form dialog that I need, though it is still blank. Is there a way to get the dialog box to show up when looking at the design so that I can add a picture box to it? When I click on "About MatchingGame" from the design file, it just lets me change the text and does not open the form dialog to let me put anything in it. How can I get the dialog form to display what I need (an image and a text field)? I have tried added open file dialog to the source code, but I could not get that to work (and it doesn't solve the problem of the text). Any ideas?
Yes, create a new Form and add it to your project. Give it a name like "MyForm". Then you can change the form in the designer.
Instead of doing Form dlg1 = new Form();, do MyForm dlg1 = new MyForm();. The rest of your code can be the same.

WPF application in one window

I am new in WPF and want to create WPF application like cookbook. I already done this and app work correctly. But I make it in this way:
First screen show buttons, which open new windows to do something. As a result i have 14 different windows. It is ok, but now i want to make it in other way.
I am trying to make one window, which will be showed at start, and change content. I divided window on two grids. First is static and is placed on bottom. It contains buttons, which represents functionality of the program. Second one will be dynamic. There i want to show content of every window. So i want to change content of this panel instead of creating new windows.
I tried to make *.cs files which will create controls in code-behind, functions and data. But my idea is not succesful and i do not know how to do this.
At all, I want to create app, which will work like this:
- if you click button "Add receip" then app will show controls to add name, ingredients and save it at the end.
- if you clik "Show receip" previous content will be replaced by list of ingredients
and etc.
I hope you will understand me.
You can create a Frame instead of second grid. Frame allows you to show pages, and not in seperate windows, in Frame itself. You can navigate the frame into the page like
mainFrame.Source = new Uri("Page1.xaml",UriKind.Relative);
This changes the frame to your page. You can change the source again, if you wanna change the page again.
Note: You can add tags to your buttons like "showReceip" and you can make just one buttonclick event for your buttons. Code will look like this.
mainFrame.Source = new Uri((sender as Button).Tag.ToString() + ".xaml",UriKind.Relative);
That takes the tag of your clicked button, add the string ".xaml" on it and take it on the source part. So, if your tag is "Page1", Source will look like "Page1.xaml" as my solution.
Appreciate the try, I hope you are looking for WPF user controls instead for separate windows. User controls are similar to windows you can create the UI and functionalities in the user control. I would like to recommend you to design the main window like the following:
<Grid>
<Canvas Name="canFunctionalButtons">
<!--Define the buttons inside this canvas
And allocate proper place for this in the UI
-->
</Canvas>
<Canvas Name="canControlContainer">
<!--This is to display the user control
Which can be changed dynamically according to the Button's click
-->
</Canvas>
</Grid>
Then you have to add click event for those buttons, which will add specific user control to the canControlContainer canvas. An example for adding an user control to this canvas is as follows, Let btnAddSomething be a button and btnAddSomething_Click be its click event then you can do something like:
private void btnAddSomething_Click(object sender, RoutedEventArgs e)
{
canControlContainer.Children.Clear(); // will remove previous contols from this canvas
// UC_AddSomething be the user control that you wanted to add here
canControlContainer.Children.Add(new UC_AddSomething());
}

c# toolstrip doesn't dock under menustrip

I have a menustrip that I create using the forms designer. I then want to programmatically add a toolstrip toolbar UNDER the menustrip. The reason is that this toolbar is a set of tools that I add as a plugin to the main application. As such, when the plugin is loaded, I create the toolbar.
When I manually add the toolstrip to the form using the forms designer, the toolstrip is correctly positioned under the menustrip. However when I add it programmatically, it snaps to the topmost part of the form, above the menustrip. Here's the code I use to programmatically add the toolstrip:
stereoBar = new ToolStrip();
stereoBar.Anchor = (AnchorStyles)(AnchorStyles.Top | AnchorStyles.Left);
//y location is set to 22, the width of the menustrip
stereoBar.Location = new System.Drawing.Point(0, 22);
stereoBar.Dock = DockStyle.Top;
stereoBar.Name = "StereoToolbar";
stereoBar.Text = "Stereo Plugin Toolbar";
stereoBar.ShowItemToolTips = true;
stereoBar.GripMargin = new Padding(2);
Controls.Add(stereoBar);
Is there anything simple I am missing here?
Thanks in advance!
As described also in this answer, when docking controls in a form the order in which you add them to the form matters; i.e. when adding multiple controls that all dock to the top, the last control that gets added will be the topmost.
So, because you add your toolstrip programmatically and your menu strip via designer, the designer code gets executed first thus having the menu strip always at the bottom.
I think there are three ways out of the dilemma:
First approach
As Hans Passant pointed out, the easiest way to get things into the right order would be to simply call
stereoBar.BringToFront();
right after you added it to the forms' controls.
Second approach
To circumvent this you could also also add the menu strip programmatically and do this after you added the tool strip.
Third approach
Another way out may be to add another container to the form (Panel or groupbox for example) via designer that also docks to the top that simply just functions as a placeholder where you add your tool strip to (so you do not add to the form directly anymore)

add one xaml based usercontrol to another on mouse event

I have three xaml files + their code behind files in my Silverlight (C#) web project.
One is the MainPage.xaml, which is what gets rendered in the browser.
The other two (lets call them Dot and Box) are custom usercontrols.
When the webpage loads, Dots get added to random locations in a sub-canvas in MainPage xml.
I would like to add a Box to a Dot's location when the user mouses over the Dot. Here is my code behind for Dot:
public partial class Dot : UserControl
{
public string grbId {get; set;}
public Dot()
{
// Required to initialize variables
InitializeComponent();
}
private void UserControl_MouseEnter(object sender, MouseEventArgs e)
{
//
//HtmlPage.Window.Alert(grbId);
MainPage mp = new MainPage();
Box idWindow = new Box();
idWindow.textBlock.Text = grbId;
// I added the following two lines because I thought it was being
// rendered behind Skymap but that is not the case.
Canvas.SetZIndex(idWindow, 5);
Canvas.SetZIndex(mp.SkyMap, -1);
idWindow.IsEnabled = true;
// Grow is animation storyboard
idWindow.Grow.Begin();
// SkyMap is a canvas inside my LayoutRoot canvas in MainPage.
mp.SkyMap.Children.Add(idWindow);
}
}
The MouseEnter event fires properly and the HtmlPage alert works just fine. But the Box never gets drawn. I have added the same code to the MainPage OnLoad event and it works fine. Can someone please tell me what I am missing? I would appreciate any help you can provide.
Please let me know if I am leaving out important information to solve the problem. Thanks!
I had searched every keyword combo I could think of before posting this question. Apparently, they were not the keywords the search engines wanted.
I was able to finally find my answer here: http://forums.silverlight.net/forums/p/123126/278060.aspx

Categories