When I create transparent applications with WebView2 c# form,
It is not possible to click on visible elements.
When I click, it clicks on the window behind.
I don't have the problem with WebBrowser
Do you have a solution ?
Thank you
//
// webView21
//
this.webView21.CreationProperties = null;
this.webView21.DefaultBackgroundColor = System.Drawing.Color.Transparent;
this.webView21.Location = new System.Drawing.Point(462, 12);
this.webView21.Name = "webView21";
this.webView21.Size = new System.Drawing.Size(337, 429);
this.webView21.Source = new System.Uri("https://***", System.UriKind.Absolute);
this.webView21.TabIndex = 2;
this.webView21.ZoomFactor = 1D;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.webBrowser1);
this.Controls.Add(this.webView21);
this.Name = "Form1";
this.Text = "Form1";
this.TransparencyKey = System.Drawing.Color.Transparent;
((System.ComponentModel.ISupportInitialize)(this.webView21)).EndInit();
this.ResumeLayout(false);
Related
I am making a form system where i need to find a panel to change it's background using string imploration. I have done something similar for a label using the code below where numberEntered is a seperate interger in the program.
Label label = Controls.Find($"Num{numberEntered}", true).OfType<Label>().FirstOrDefault();
label.Text = "Text"
How can I do something similar for a panel where where I can find a panel using a seperate variable in the name? Such as $"Panel{number}"
I have already tried this:
Panel panel = Controls.Find($"Ans{answerNum}Panel", true).OfType<Panel>().FirstOrDefault();
panel.BackgroundImage = Programming_Project.Properties.Resources.MutliChoiceCorrectSelected;
However it throws a NullReferenceException. Any help is much appreciated!
Try it this way please:
String ctlName = $"Ans{answerNum}Panel";
Panel panel = this.Controls.Find(ctlName, true).FirstOrDefault() as Panel;
if (panel != null) {
panel.BackgroundImage = Programming_Project.Properties.Resources.MutliChoiceCorrectSelected;
}
else {
MessageBox.Show("Unable to find " + ctlName);
}
You can try to open Form1.Designer.cs where Form1 is your form name.
Then find the panel code and modify it.
That's how I tried and it worked.
It should look something like this:`
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel1
//
**this.panel1.BackColor = System.Drawing.SystemColors.ActiveCaption;**
this.panel1.Location = new System.Drawing.Point(169, 41);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(427, 190);
this.panel1.TabIndex = 0;
this.panel1.Paint += new
System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
I have Windows Form Application. There are 2 standart controls on a form as linklabel and reportviewer. Data represented on reportViewer control sometimes so long and there possible some scrolling to keep all data for reading. It's normal situation.
But I need simple feature, when user is scrolling up or down, linkLabel should move depend scrolling values to up or down, synchronously reportViewer content. LinkLabel location must be fixed comparatively reportViewer
InitializeComponent method included:
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(HRCard));
this.reportViewer1 = new Microsoft.Reporting.WinForms.ReportViewer();
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.SuspendLayout();
//
// reportViewer1
//
this.reportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.reportViewer1.LocalReport.ReportEmbeddedResource = "Kadr_Azerenerji.Report1.rdlc";
this.reportViewer1.Location = new System.Drawing.Point(0, 0);
this.reportViewer1.Name = "reportViewer1";
this.reportViewer1.Size = new System.Drawing.Size(1020, 730);
this.reportViewer1.TabIndex = 0;
this.reportViewer1.RenderingComplete += new Microsoft.Reporting.WinForms.RenderingCompleteEventHandler(this.reportViewer1_RenderingComplete);
this.reportViewer1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.reportViewer1_Scroll);
//
// linkLabel1
//
this.linkLabel1.AutoSize = true;
this.linkLabel1.Location = new System.Drawing.Point(160, 314);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(45, 15);
this.linkLabel1.TabIndex = 2;
this.linkLabel1.TabStop = true;
this.linkLabel1.Text = "Diplom";
this.linkLabel1.Visible = false;
this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
//
// HRCard
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(1020, 730);
this.Controls.Add(this.linkLabel1);
this.Controls.Add(this.reportViewer1);
this.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "HRCard";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Azərenerji Kadr";
this.TransparencyKey = System.Drawing.Color.LavenderBlush;
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.HRCard_FormClosing);
this.Load += new System.EventHandler(this.HRCard_Load);
this.Scroll += new System.Windows.Forms.ScrollEventHandler(this.HRCard_Scroll);
this.ResumeLayout(false);
this.PerformLayout();
How can I do this ?
I have a UserControl named "UserControl1" with a label inside it and a custom property:
[Browsable(true)]
public new string Text
{
get { return label1.Text; }
set { label1.Text = value; }
}
public UserControl1()
{
InitializeComponent();
}
This UserControl is used in a form named "Form1".
In the designer appears the property but when I write some text and build the application the text is cleared. I can see, the property isn't written in the Form1.Designer.cs.
If I change the property name to some other word all is ok.. Note the "new" keyword to override the base variable..
I have found a similar question here but there is no solution.
Greetings!
EDIT: There is no hardcoded value:
UserControl1.Designer.cs:
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(64, 63);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 0;
//
// UserControl1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label1);
this.Name = "UserControl1";
this.Size = new System.Drawing.Size(181, 136);
this.ResumeLayout(false);
this.PerformLayout();
Form1.Designer.cx:
//
// userControl11
//
this.userControl11.Location = new System.Drawing.Point(35, 43);
this.userControl11.Name = "userControl11";
this.userControl11.Size = new System.Drawing.Size(181, 136);
this.userControl11.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.userControl11);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
To reproduce the problem just create a new windows form application, create an user control with a label inside it and with the property named "Text".
Try using override instead of new for the Text property and include the DesignerSerializationVisibility attribute:
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override string Text {
get { return label1.Text; }
set { label1.Text = value; }
}
Look inside InitializeComponent(). It is most likely hard-coding a default value when you place the control on the design surface.
I have created a Password field in C# as
public System.Windows.Forms.TextBox passwordBox;
other setting made for this field are
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.CornflowerBlue;
this.ClientSize = new System.Drawing.Size(381, 199);
this.Controls.Add(this.button1);
this.Controls.Add(this.panel1);
this.Controls.Add(this.label1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Progpassword";
this.Text = "Programmer Password";
this.TransparencyKey = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
this.Load += new System.EventHandler(this.Progpassword_Load);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
I am not able to read the text entered in the TextBox
I am reading the value using following line
string text = PasswordBox.Text;
Is this the right way to read the password field.
Yes text = passwordBox.Text; is only that way how you can get it!
Is there any way to add a System.Windows.Controls.TextBox to GroupBox controls in C#?
I tried the following but it doesn't show up in the groupbox:
public System.Windows.Controls.TextBox textBox6 = new System.Windows.Controls.TextBox();
public System.Windows.Controls.TextBox textBox7 = new System.Windows.Controls.TextBox();
public ElementHost sumtext = new ElementHost();
public ElementHost loctext = new ElementHost();
private void Form1_Load(object sender, EventArgs e)
{
textBox6.Name = "Summary";
textBox7.Name = "Location";
textBox6.FontFamily = new System.Windows.Media.FontFamily("Microsoft Sans Serif");
textBox6.FontSize = 12;
textBox6.SpellCheck.IsEnabled = true;
textBox7.FontFamily = new System.Windows.Media.FontFamily("Microsoft Sans Serif");
textBox7.FontSize = 12;
textBox7.SpellCheck.IsEnabled = true;
groupBox4.Controls.Add(sumtext);
sumtext.Dock = DockStyle.None;
sumtext.Width = 246;
sumtext.Height = 35;
sumtext.Child = textBox6;
sumtext.Location = new Point(3, 33);
sumtext.Visible = true;
sumtext.Enabled = false;
groupBox4.Controls.Add(sumtext);
groupBox4.Controls.Add(loctext);
loctext.Dock = DockStyle.None;
loctext.Width = 246;
loctext.Height = 35;
loctext.Child = textBox7;
loctext.Location = new Point(3, 90);
loctext.Visible = true;
loctext.Enabled = false;
this.Controls.Add(sumtext);
this.Controls.Add(loctext);
}
I need to use System.Windows.Controls.TextBox rather than Form.TextBox as I need it for spell check.
Any help would be greatly appreciated!
I changed the Enabled property of the sumtext, and removed the other box to shorten it:
This code works for me:
public Form1()
{
this.Load += new System.EventHandler(this.Form1_Load);
}
public System.Windows.Controls.TextBox textBox6 = new System.Windows.Controls.TextBox();
public ElementHost sumtext = new ElementHost();
private System.Windows.Forms.GroupBox groupBox4;
private void Form1_Load(object sender, EventArgs e)
{
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.SuspendLayout();
//
// groupBox4
//
this.groupBox4.Location = new System.Drawing.Point(57, 63);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(591, 238);
this.groupBox4.TabIndex = 0;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "groupBox1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(706, 478);
this.Controls.Add(this.groupBox4);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
textBox6.Name = "Summary";
textBox6.FontFamily = new System.Windows.Media.FontFamily("Microsoft Sans Serif");
textBox6.FontSize = 12;
textBox6.SpellCheck.IsEnabled = true;
groupBox4.Controls.Add(sumtext);
sumtext.Dock = DockStyle.None;
sumtext.Width = 246;
sumtext.Height = 35;
sumtext.Child = textBox6;
sumtext.Location = new Point(3, 33);
sumtext.Visible = true;
sumtext.Enabled = true;
groupBox4.Controls.Add(sumtext);
}
Is this code actually getting called? Has groupbox 4 been added to the form yet?
You should not be adding your ElementHost controls to your Form AND your GroupBox, it appears to be confusing .NET. Keeping your original code exactly as-is but commenting out these two lines makes it work:
//this.Controls.Add(sumtext);
//this.Controls.Add(loctext);
Also... I don't think it's hurting anything, but you don't need to do this twice:
//groupBox4.Controls.Add(sumtext);