Draw a toolstrip on an empty form. Add a SplitButton on this toolstrip. Will be working as a login in button later on.
On this SplitButton I want to remove the dropdown in the start position. The only thing you can do is to login. Once you have logged in, the dropdown is populated with items like "Change Password", "Update Profile" and so on.
I have tried put the property:
loginButton.DropDownButtonWidth = 0;
this almost removes the drop down, it is gone, but its a very ugly dot on the right, which seems like to be one pixel left from the drop down corner. See images below:
I have tried a lot of other properties to remove the drop down, but no progress. And I cant find anything similar when I google.
I got excellent help fix another problem with the tool strip a few days back, the tool strip had a drawing problem too in its default state. but is removed if you do override a method, see this post:
Toolstrip drawing problem
Does anyone know how I can remove the ugly dot, or remove the drop down some other way?
Full source, one line essentially with the SplitButton named loginButton:
using System;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
loginButton.DropDownButtonWidth = 0;
}
}
}
You can use your own renderer to try to achieve that:
private class NoArrowRenderer : ToolStripProfessionalRenderer {
protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e) {
if (e.Item.GetType() != typeof(ToolStripSplitButton)) {
base.OnRenderArrow(e);
}
}
}
Then apply it to your ToolStrip:
toolStrip1.Renderer = new NoArrowRenderer();
Related
My question refers to the previous one:
a link
I want to add the scrolling option to the FlowLayautPanel control, but I don't know how to associate adding a new row with UserControl, with VerticalScroll so that after moving it there will be visible rows that are not visible.
Below I have tried on my own to add the option of scrolling, but the content of FlowLayaoutControl shifts slower than owl, and when it reaches the end, you can not see the last lines.
public partial class ImportManager : Form
{
public ImportManager()
{
InitializeComponent();
this.flowLayoutPanel1.VerticalScroll.Visible = true;
this.flowLayoutPanel1.VerticalScroll.Maximum = 100;
}
private void DodajWierszButton_Click(object sender, EventArgs e)
{
this.flowLayoutPanel1.Controls.Add(new importRow());
this.flowLayoutPanel1.VerticalScroll.LargeChange -= 1;
}
}
I would add that I am a beginner in window programming and the solution is probably trivial, but I am not able to solve it at the moment.
I would like the FlowLayoutPanel to be able to send lines.
I would like a transparent overlapped non-clipped image. I have one PictureBox overlapping another, as shown in this SO thread.
The solution, which makes sense, sets the parent of the top image to the bottom image. The top image is then set to have a transparent background. The technique works perfectly, just setting the parent of the top image to that of the bottom clips the top image to the area of the bottom image.
Top Image Parent Property NOT Set to the Bottom Image
Now, here is what happens if the top image parent property gets set to the bottom image.
I do not want the top image clipped.
I would volunteer the entire Visual Studio 2019 (VS2019) project, but not sure how to post it.
Here is the code:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ImageOverlap
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
private void FrmMain_Load(object sender, EventArgs e)
{
this.ImgTop.Parent = this.ImgBottom;
this.ImgTop.BackColor = Color.Transparent;
//this.ImgTop.BringToFront();
this.ChangeX.Value = 430;
this.ChangeY.Value = 15;
}
private void ChangeX_ValueChanged(object sender, EventArgs e)
{
this.ImgTop.Left = (int)this.ChangeX.Value;
}
private void ChangeY_ValueChanged(object sender, EventArgs e)
{
this.ImgTop.Top = (int)this.ChangeY.Value;
}
}
}
I put 2 NumericUpDown controls to better adjust the position of the finger pointer.
The call to method BringToFront() can be deleted, as does nothing, just above as mentioned in a couple of answers and used for testing.
UPDATE
I do NOT want to stretch the bottom image. I want to see the form background.
I also realize that the hand pointer is out of bounds of the bottom (parent) image. As such, the hand pointers gets clipped, cut off.
I want to the entirety of the top image to show, just the part of the top image, which overlaps the bottom image to be transparent.
Using what has got to be the world's best app, Paint.Net, here is what I want, also in a nice reusable code format.
My thought towards a solution is at the moment to make a programmatic copy of the hand pointer and overlay that using onto the form just clipping the left portion, which overlaps the bottom image. I think this idea might work, will post as answer if it works.
This answer can probably be optimized and made more reusable, but it works.
I created a copy of the top control. I then used this updated code, which includes a reusable method.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ImageOverlap
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
private void FrmMain_Load(object sender, EventArgs e)
{
this.ImgTop.Parent = this.ImgBottom;
this.ImgTop.BackColor = Color.Transparent;
this.ImgTop.BringToFront();
this.ChangeX.Value = 430;
this.ChangeY.Value = 15;
}
private void ChangeX_ValueChanged(object sender, EventArgs e)
{
this.SetOverlayImageLocation((int)this.ChangeX.Value, this.ImgTop.Top);
}
private void ChangeY_ValueChanged(object sender, EventArgs e)
{
this.SetOverlayImageLocation(this.ImgTop.Left, (int)this.ChangeY.Value);
}
private void SetOverlayImageLocation(int newX, int newY)
{
this.ImgTop.Left = newX;
this.ImgTop.Top = newY;
Point ptImageAtParent = new Point(this.ImgTop.Left + this.ImgBottom.Left, this.ImgTop.Top + this.ImgBottom.Top);
this.ImgTopCopy.Location = ptImageAtParent;
this.ImgTopCopy.SendToBack();
}
}
}
I am thinking that .Net probably has a nice method/property to get the point relative to the parent. I did that in a brute force method. I then set the copy to the back. The location of the copy is set relative to the parent. The trick is that the copy has the parent property set to the main control.
Here is the runtime visual that I got, no Paint.Net involved; looks identical, which is the objective.
The nice part is that the NumericUpDown controls work flawlessly moving the combined image, which to the user appears as one image.
You want the entire image render on bottom image, if yes it means your problem is calculation of top image position.
this.ImgTop.Parent = this.ImgBottom;
this.ImgTop.BackColor = Color.Transparent;
this.ImgTop.BringToFront();
this.ImgTop.Top = 0;
this.ImgTop.Left = ImgBottom.Width - ImgTop.Width;
I see your replay to Reza, sorry for misunderstood. you set the parent of top image to bottom image. the control can't do any more actions outside of parent area after this. if you want to do that you can dynamically split your image into to separate image controls, one of theme inside the bottom image and another outside and control position of both of theme or implement own control maybe by the help of polygons.
I have a winform named "QuickMenu". This QuickMenu form contains collapse and expands buttons. Please check the attachment screenshot.
I want to open a User Control WinForm by clicking the button on the "QuickMenu" form. I have written the following code in QuickMenu.cs:
Public partial class QuickMenu : Form
{
private CollectionReport collection;
}
public QuickMenu()
{
InitializeComponent();
collection = new CollectionReport();
}
private void resCollection_Click(object sender, EventArgs e)
{
collection.Dock = DockStyle.Fill;
this.Controls.Add(collection);
timer1.Start();
}
Note: This code is written for the "Collection" button.
After writing this code, the output is the following screenshot.
How can I show the User Control in full screen?
The User Control is supposed to look like:
Note: Orders, Collection, Delivery and Setup buttons are in another form named "AllSettingsForm". And also, this button has a separate form that is called into the AllSettingsForm. Look at the solution, and I hope you will understand what I mean.
Replace your default constructor by below code
public dataContext() : base("name=DefaultConnection")
{
}
If you are using .NET Core then try this:
public dataContext(DbContextOptions dbContextOptions): base(dbContextOptions)
{
}
Write the following code for the resCollection_Click button. This is the solution I found and the following code works for me.
private void resCollection_Click(object sender, EventArgs e)
{
collection.Dock = DockStyle.Fill;
AllSettingsForm allSettings = new AllSettingsForm();
allSettings.Controls.Add(collection);
this.collection.Visible = true;
this.collection.BringToFront();
allSettings.Show();
timer1.Start();
}
I have no better way of explaining it, but I want to implement a container that only is shown after the user clicked "Advanced" or a plus sign somewhere in the dialog. I have a login form and want to add some "Advanced" settings. But they should normally out of view.
Of course, the dialog has to resize nicely to hold the extended content.
How should I go to implement such a thing. I have tried some Google searches, but can't find the right search words. Windows doesn't seem to have it by default.
as John Willemse suggested, I ended up creating the functionality myself. I added a Panel in the form that I just set visible or invisible.
In the Form's constructor (to hide it on first view):
public FrmLogin() {
InitializeComponent();
pnlAdvanced.Visible = false;
Height -= pnlAdvanced.Height;
}
Then, I added a LinkLabel with this Clicked handler:
private void linkLabel1_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs e) {
if (pnlAdvanced.Visible == false) {
Height += pnlAdvanced.Height;
pnlAdvanced.Visible = true;
} else {
Height -= pnlAdvanced.Height;
pnlAdvanced.Visible = false;
}
}
Works perfectly and no extra code needed.
I am very new to C# programming. I come from autoit, and other scripting languages, the transition has been most difficult. Anyway I am working on a control in a windows form, basically I want it to be a LinkLabel control, that when you click it, it will become a textbox, once you enter your name, and either hit enter, or tab, it will set your name as the linklabel. But, I will have 10 of these controls on a form, and the way I have done it, it has taken three methods per control, so that is a lot of code, I'm sure I'm just doing it wrong, but here is what i have:
namespace Program
{
public partial class formMain : Form
{
public formMain()
{
InitializeComponent();
}
private void linkLabelPlayerName1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
this.linkLabelPlayerName1.Hide();
this.textBoxPlayerName1.Show();
this.textBoxPlayerName1.Focus();
this.textBoxPlayerName1.KeyPress += new KeyPressEventHandler(textBoxPlayerName1_KeyPress);
this.textBoxPlayerName1.LostFocus += new EventHandler(textBoxPlayerName1_LostFocus);
}
private void textBoxPlayerName1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
this.linkLabelPlayerName1.Text = this.textBoxPlayerName1.Text;
this.textBoxPlayerName1.Hide();
this.linkLabelPlayerName1.Show();
}
}
private void textBoxPlayerName1_LostFocus(object sender, EventArgs e)
{
this.linkLabelPlayerName1.Text = this.textBoxPlayerName1.Text;
this.textBoxPlayerName1.Hide();
this.linkLabelPlayerName1.Show();
}
}
}
I'm sure there is a way to use the last two methods between all 10 controls, so they don't have to be rewritten for each control. That is, textBoxPlayerName1_LostFocus() and textBoxPlayerName2_LostFocus().
Welcome to object orientated programming :).
You should created a derived class to encapsulate the functionality. For example:
class EditableText : UserControl
{
private LinkLabel lblName;
private TextBox txtName;
public EditableText()
{
// Construct objects, attach events and add them
// as children to this object
}
// Return the text of encapsulated TextBox
public string Text
{
get { return txtName.Text; }
}
}
Now you are able re-use this class in different areas, that's what object orientated programing all about!
Right-click on the windows forms application in the Solution Exporer, and select Add, then User Control...
Type in a name for the new control, like LinkLabelTextBox
This will give you a space to work in that looks like a Form, but without borders. This is your new control. Put your LinkLable and TextBox on this new control exactly as you put them in the window, and give them the functionality that you want. Then replace all your existing controls with instances of this new control. You will create 10 of these, instead of creating ten LinkLabels and ten TextBoxes. And all of the functionality that you want will be built-in to your new control, so that code does not need to be repeated.
Instead of a linkLabelPlayerName1 and textBoxPlayerName1, you will have a linkLabelTextBoxPlayerName1, and none of the Show, Hide, Focus stuff will clutter your form code.
Also, be sure to include a public Text property so you can get the value that the user typed out of this control.
Create your own Control with the functionality.
Your code is correct.
To make it cleaner, you should move it to a separate UserControl, and set the Text property to the textbox's value.