I wrote a notepad. But I have a problem that I did not find an answer anywhere else. When the status bar is Enable, the load scroll is hidden behind the status bar. And this is a bug.
here design details
// StatusBar1
//
this.StatusBar1.Items.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabel1,
this.statusbar_lbl});
this.StatusBar1.LayoutStyle =
System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow;
this.StatusBar1.Location = new System.Drawing.Point(0, 161);
this.StatusBar1.Name = "StatusBar1";
this.StatusBar1.Size = new System.Drawing.Size(480, 22);
this.StatusBar1.TabIndex = 1;
this.StatusBar1.Visible = false;
any help appreciated
Related
In the following code I used errorProvider.SetError(control, message) to display the message, but only the Icon is shown, the message is not shown, what is wrong?
Is there a way to adjust the left margin of the error message only? (I know you can SetIconPadding, but I only want left margin to be changed)
public static DialogResult ShowDialog()
{
var inputBox = new Form { ClientSize = new Size(520, 225), FormBorderStyle = FormBorderStyle.FixedDialog };
var panel = new TableLayoutPanel { Size = new Size(460, 100), Location = new System.Drawing.Point(45, 15) };
var errorProvider = new ErrorProvider { Icon = SystemIcons.Exclamation, BlinkStyle = ErrorBlinkStyle.NeverBlink };
errorProvider.SetIconAlignment(panel, ErrorIconAlignment.BottomLeft);
var okButton = new Button
{
Size = new System.Drawing.Size(70, 30),
Location = new Point(330, 180),
Text = "OK"
};
okButton.Click += new EventHandler((sender, e) => { errorProvider.SetError(panel, "Test Error"); });
inputBox.Controls.Add(panel);
inputBox.Controls.Add(okButton);
return inputBox.ShowDialog();
}
Let me explain about ErrorProvider.
ErrorProvider in Windows Application has following behaviour.
It will display error icon as per configuration.
It will display error message that you have set once you put your mouse cursor on it.
The behaviour you want is too display error message along with icon.
There is one solution build your own control just like ErrorProvider.
so I managed to build my own simple user control. Basically it is a custom Button containing a child Label control on top of it. The button works as how it should be during runtime.
However during design time I got an issue whenever I cut-and-paste that button (let's say I want to move it from Panel1 to Panel2 by cut-and-paste).
The button itself retains its properties such as background color, etc, but the child Label inside it is reinitialized everytime we paste it, so the text and color inside that label changed back to its default value.
The value of the labels text is set by "Text" property which overrides Text property of the UserControl such as follows :
private String _text = "Button";
[Browsable(true), Description("Sets the text displayed on the button"), Category("Display Settings")]
public override String Text {
get => _text;
set {
_text = value;
lb_Text.Text = _text;
}
}
Is there a way to retain child control properties during cut-and-paste in the Designer view?
Below is the code generated for InitializeComponent() section of the UserControl, which will be called whenever it is added to a form. Details aside, I acknowledged that default text and color values is re-initialized there, so I'm not sure how we replace those during cut-and-paste.
private void InitializeComponent()
{
this.lb_Text = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lb_Text
//
this.lb_Text.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(127)))), ((int)(((byte)(127)))), ((int)(((byte)(127)))), ((int)(((byte)(127)))));
this.lb_Text.Dock = System.Windows.Forms.DockStyle.Fill;
this.lb_Text.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold);
this.lb_Text.ForeColor = System.Drawing.Color.Black;
this.lb_Text.Location = new System.Drawing.Point(0, 0);
this.lb_Text.Name = "lb_Text";
this.lb_Text.Size = new System.Drawing.Size(200, 50);
this.lb_Text.TabIndex = 1;
this.lb_Text.Text = "Button";
this.lb_Text.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// MomentaryButton
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = global::HMIControls.Properties.Resources.Button_Normal;
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.Controls.Add(this.lb_Text);
this.Name = "MomentaryButton";
this.Size = new System.Drawing.Size(200, 50);
this.ResumeLayout(false);
}
So I have a Form that is a scale A4 page that allows users to drag and drop controls on the form for printing.
IE where ever the control is on the form its location is used to print the controls data, eg: File name or image, to that point of an A4 page.
However I have created a number of templates for the form that sets the controls in certain locations and adds in any missing controls. When the templates are selected any extra controls don't show on the form even though I call the Invalidate() method.
Here is my code for the method that adds the controls to the Form:
private void standardIDToolStripMenuItem_Click(object sender, EventArgs e)
{
selectedID = true;
selectedInvoice = false;
selectedLetter = false;
lblName.Visible = true;
lblDOB.Visible = true;
lblUID.Visible = true;
lblName.Location = new Point(200, 100);
lblDOB.Location = new Point(200, 125);
lblUID.Location = new Point(200, 150);
lblName2.Text = lblName.Text;
lblName2.Location = new Point(60, 750);
lblName2.Enabled = true;
lblName2.Visible = true;
lblDOB2.Text = lblDOB.Text;
lblDOB2.Location = new Point(60, 775);
lblDOB2.Enabled = true;
lblDOB2.Visible = true;
lblUID2.Text = lblUID.Text;
lblUID2.Location = new Point(60,800);
lblUID2.Enabled = true;
lblUID2.Visible = true;
hidden1.Location = new Point(300, 100);
DOBHidden.Location = new Point(300, 125);
UIDHidden.Location = new Point(300, 150);
#region ID Background placeholder
PictureBox backPic = new PictureBox();
backPic.Location = new Point(24, 48);
backPic.ForeColor = System.Drawing.Color.PaleGreen;
backPic.Size = new Size(504, 176);
backPic.Visible = true;
backPic.Show();
backPic.SendToBack();
this.Invalidate();
#endregion
}
Why will the new controls not appear on the form when I have called the Invalidate() method to force it to repaint?
It seems that you don't add them to Controls:
please try this on every control after you have specified location and the rest of the control initialization:
this.Controls.Add(lblName)
Mong Zhu seems to be right and I also suggest you to catch a glimpse of some kind of report designer if you can use some third-part libaries ( I'm not sure if winforms privides something like DevExpress reports for example)
I guess that it will be helpful with stuff you are doing in your project.
I am using a gridview in a C# windows application. One of the cells has a long string of text (see below) but whenever it is bound to the grid the cell gets cropped and the scrollbar does not get to end of the grid to display the full text. The scrollbar doesn't scroll smoothly when dragging with a mouse either.
I tried different combinations for RowSize and ColumnSize` modes, but with no luck.
void FillGrid()
{
DataTable tasktable = new DataTable();
tasktable.Columns.Add("Logged By", typeof(string));
tasktable.Columns.Add("Date", typeof(DateTime));
tasktable.Columns.Add("Notes", typeof(string));
DataRow dr1;
//for (int i = 0; i < 100; i++)
//{
dr1 = tasktable.NewRow();
dr1[0] = "Sunit Shah";
dr1[1] = System.DateTime.Now;
dr1[2] = "Test Note";
tasktable.Rows.Add(dr1);
//}
dr1 = tasktable.NewRow();
dr1[0] = "Sunit Shah";
dr1[1] = System.DateTime.Now;
dr1[2] = "Test Note";
dr1[2] = "Paul Pogba will have a medical at Manchester United on Monday after
Juventus granted permission for him to seal a potential world record
transfer.Juventus manager Massimo Allegri refused to be drawn further
on the transfer when he was asked about it in his post-match press
conference following a friendly against West Ham at the London Stadium,
but an official at the Italian club confirmed they had authorised the
midfielder to have United doctors assess him ahead of the move.
Allegri merely said: ‘I spoke about Pogba the day before, we have
just finished a match and I don’t know much more, we will see on Monday
if he is a still Juventus player.’";
tasktable.Rows.Add(dr1);
DataTable fillNotesGrid = new DataTable();
fillNotesGrid = (from row in tasktable.AsEnumerable()
orderby row.Field<DateTime>("Date") descending
select row).CopyToDataTable();
dgvSIDetailsNotes.DataSource = fillNotesGrid;
}
From what I can gather, it looks like your problem isn't that it's truncating the data, it's that it's snapping to cells when you scroll, so it's right at the top of every cell when you scroll. If it's it's too big for the space available, you'll only see as much of the top part of that row as you can fit. Basically, it behaves like Microsoft Excel.
I don't think there's a way to turn off this behaviour in the standard DataGridView control.
HOWEVER, as a workaround you can add your DataGridView to a System.Windows.Forms.Panel, and make the Panel do your scrolling for you!
Simply make the DataGridView a child of the Panel control, and set the Panel's AutoScroll property to true and the DataGridView's AutoSize property to true and that should do the trick.
EDIT
I have included some source code to try and make things clear.
This is source code from the form (with the body of FillGrid()) omitted as it's identical to the source code in your question).
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True; //I'm assuming this is already set in your own source code as the cell is wrapping its text in your screenshot.
panel1.AutoScroll = true;
dataGridView1.AutoSize = true;
FillGrid();
}
void FillGrid()
{
...
}
}
This is how the controls are created in Form1.Designer.cs:
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.Panel panel1;
This is the generated InitializeComponent() method in the Designer.
private void InitializeComponent()
{
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.panel1 = new System.Windows.Forms.Panel();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(3, 3);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(145, 122);
this.dataGridView1.TabIndex = 0;
//
// panel1
//
this.panel1.Controls.Add(this.dataGridView1);
this.panel1.Location = new System.Drawing.Point(12, 12);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(260, 126);
this.panel1.TabIndex = 1;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
This should be everything you need to replicate this solution in a test project.
If you're experiencing issues with this in your main project then you may have other code that is interfering.
I have a class which handles a sort of user control popup, which works by inheriting from System.Windows.Forms.ToolStripDropDown. This has worked for the popup type i had currently, of which i shall detail below;
First, is the class which i use to hold the user control in a popup type style;
public class PopupWindow : System.Windows.Forms.ToolStripDropDown
{
private System.Windows.Forms.Control _content;
private System.Windows.Forms.ToolStripControlHost _host;
public PopupWindow(System.Windows.Forms.Control content)
{
//Basic setup...
this.AutoSize = false;
this.DoubleBuffered = true;
this.ResizeRedraw = true;
this.BackColor = content.BackColor;
this._content = content;
this._host = new System.Windows.Forms.ToolStripControlHost(content);
//Positioning and Sizing
this.MinimumSize = content.MinimumSize;
this.MaximumSize = content.Size;
this.Size = content.Size;
content.Location = Point.Empty;
//Add the host to the list
this.Items.Add(this._host);
}
}
as we can see here, i'm simply passing a control to it, and letting it do the work. When using this on an "onclick" popup, like so, it works fine;
public void Popup(object sender, MouseEventArgs e, other params)
{
DevicePopup popupDevice = new DevicePopup();
//do stuff to the control here before displaying
PopupWindow popup = new PopupWindow(popupDevice);
popup.Show(Cursor.Position);
}
and calling it like so;
this.Controls[btnAdd.Name].MouseClick += (sender, e) =>
{
int index = temp;
generatePopup.Popup(sender, e, mDevices[index], this);
};
doing this successfully creates the popup user control at my mouse click, as intended.
However, i'm now trying to use a second type of popup which spawns when something happens. Below is my new popup class, and calling it;
public void AlarmNotificationPopup(IDeviceInterface device)
{
try
{
AlarmNotification ANotification = new AlarmNotification();
//do stuff to the control again before displaying
PopupWindow popup = new PopupWindow(ANotification);
popup.Show(100, 100);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
AlarmNotificationPopup(device);
However, this popup doesn't render / create properly, and looks like so;
I'm not entirely sure how to fix this. anyone have any ideas?
A couple of things to try:
I don't think you need your "Basic Setup", so comment that out. Also, try setting your margins and paddings:
public PopupWindow(Control content) {
// Basic setup...
// this.AutoSize = false;
// this.DoubleBuffered = true;
// this.ResizeRedraw = true;
// this.BackColor = content.BackColor;
this._content = content;
this._host = new ToolStripControlHost(content);
this._host.Margin = new Padding(0);
this._host.Padding = new Padding(0);
this.Padding = new Padding(0);
this.Margin = new Padding(0);
//Positioning and Sizing
this.MinimumSize = content.MinimumSize;
this.MaximumSize = content.Size;
this.Size = content.Size;
content.Location = Point.Empty;
//Add the host to the list
this.Items.Add(this._host);
}
Make sure your AlarmNotification has its MinimumSize property set.
If that doesn't help solve the problem, then you probably need to document what the AlarmNotification class is doing.