So I have a problem with dynamically adding in a textbox, on button click, at a specific location. I've tried using system.windows.forms and system.web.ui.webcontrols namespaces however I still get textbox1.location underlined in red.
protected void Button1_Click(object sender, EventArgs e)
{
System.Web.UI.WebControls.TextBox textBox1 = new System.Web.UI.WebControls.TextBox();
textBox1.Location = new Point(15, 15);
this.Controls.Add(textBox1);
}
And if I use system.windows.forms for the declaration of my textbox, this.Controls.Add(textBox1) will be underlined red and it says cannot convert from windows forms to web controls.
Please help! I've researched everywhere but I cant seem to find a solution.
You can't set the position of a control in ASP.NET. It isn't Windows Forms, which is for Desktop apps. ASP.NET ends up to be HTML and Javascript which need a little more work for you to get what you want.
If you want to set the control on a specific position, you have to append a class to it. Then style that class and determine its positioning using CSS.
Related
I am using windows form to build an app that draws the form controls based on the connected device dynamically. So I have a tab control and when the user select tab3 for instance the tab page content will be drawing based on connected device for example add two text boxes and a button. How can I do this. I would like also to know how to position those controls after they are created.
private void tabPage3_Click(object sender, EventArgs e)
{
TextBox text = new TextBox();
this.tabPage3.Controls.Add(text);
}
As you just stated, you create your Controls like in your example. Positioning is achieved by the Left and Top Properties of your freshly created control. BUT, my advise is, it will be easier to use predefined UserControls and add them dynamically, because I think you don't have nearly unlimited types of devices.
If you are curious how Visual Studio Designer is creating those code, just look up Designer.cs in InitializeComponent()
I tried to make a similar login pop up window using PopUp, MessageDialog and ContentDialog. But none of them satisfied my requirement. Please tell me how to achieve a similar popup window which has textbox and buttons in it using XAML or C# for building Windows Universal App.
Thank you in advance !
Pls see the box here. It is movable by mouse dragging also:
http://postimg.org/image/ucjm8hsk5/
You could achieve the dragging feature by using the Manipulation events and the Projection property.
I suggest you to use a Border that will contain all of your controls (in a Grid inside your Border for example) and set the ManipulationMode property to All.
Then attach a method to the ManipulationDelta event of your Border with the following code:
private void Border_OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
var border = (Border)sender;
var currentProjection = border.Projection as PlaneProjection ?? new PlaneProjection();
border.Projection = new PlaneProjection() { GlobalOffsetX = currentProjection.GlobalOffsetX + e.Delta.Translation.X, GlobalOffsetY = currentProjection.GlobalOffsetY + e.Delta.Translation.Y };
}
I am creating a project using VS.NET (C#) with many forms that contain textboxes and associated labels. I have created the association through an exposed property I created for the textbox which contains the label name. The problem is that each time I add a textbox at design-time I have to add a label and then enter the label name into the property of the textbox. I would much rather do this dynamically at design-time when I create the textbox, much like the old VB textbox add. I have been scouring the net for a way to dynamically add a label whenever I add a textbox at design-time without finding any acceptable solutions. I found an answer on this site that suggested adding a user control containing a textbox and label, and though it is probably the best solution I have found, I think it restricts me more than I would like. Do I have to go through some full-blown custom designer to do this hopefully simple task?
TIA
Although I like the solution that uses UserControl better (simpler and easier to handle), but there may be some cases where not creating one more thing that will eat the resources is preferable (for example if you need a lot of such label-textbox pairs on one form).
The simplest solution I came up with is as follows (the label shows in the designer after you build the project):
public class CustomTextBox : TextBox
{
public Label AssociatedLabel { get; set; }
public CustomTextBox():base()
{
this.ParentChanged += new EventHandler(CustomTextBox_ParentChanged);
}
void CustomTextBox_ParentChanged(object sender, EventArgs e)
{
this.AutoAddAssociatedLabel();
}
private void AutoAddAssociatedLabel()
{
if (this.Parent == null) return;
AssociatedLabel = new Label();
AssociatedLabel.Text = "Associated Label";
AssociatedLabel.Padding = new System.Windows.Forms.Padding(3);
Size s = TextRenderer.MeasureText(AssociatedLabel.Text, AssociatedLabel.Font);
AssociatedLabel.Location = new Point(this.Location.X - s.Width - AssociatedLabel.Padding.Right, this.Location.Y);
this.Parent.Controls.Add(AssociatedLabel);
}
}
Although it isn't a complete solution, you need to code the additional behaviour such as moving the label with the textbox, changing the location of the label when its text changes, removing the label when the textbox is removed, and so on.
Another solution would be to not use the label at all, and just draw the text beside the textbox manually.
I'm afraid not, you would have to use either UserControl or CustomControl as there is no way to add a TextBox and associated Label at the same time
I have a .net Windows forms project that includes the System.Windows.forms.WebBrowser control to allow the user to do some editing of HTML content. When this control is in edit mode Elements such as div or span can be drag-and-drop edited, but selecting an element and typing Delete does nothing.
I have seen a few posts that talk about making this work in C++ but they are not very detailed. Example http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/1f485dc6-e8b2-4da7-983f-ca431f96021f/
This next post talks about using a function called TranslateAccelerator method to solve similar problems in MFC projects. http://vbyte.com/iReader/Reader.asp?ISBN=0735607818&URI=/HTML/chaab.htm
Does anyone have a suggestion on how to make the delete key work in C# or VB for a windows forms project?
Here is my code to create the WebBrowser content:
WebBrowser1.Navigate("about:blank") ' Initializes the control
Application.DoEvents
WebBrowser1.Document.OpenNew(False).Write("<html><body><span>Project Title</span><input type='text' value='' /></body></html>")
WebBrowser1.ActiveXInstance.Document.DesignMode = "On" ' Option Explicit must be set to off
WebBrowser1.Document.Body.SetAttribute("contenteditable", "true")
Thanks
Well the problem was that one of the control properties, "WebBrowserShortcutsEnabled" was set to false. Thanks everyone for your help, there is no way anyone could have guessed that so I get a big "DUH!". I did find a way to make this work in c# where the code would look like this:
public Form1() {
InitializeComponent();
webBrowser1.Navigate("about:blank"); // Initializes the webbrowser control
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
mshtml.IHTMLDocument2 doc = webBrowser1.Document.DomDocument as mshtml.IHTMLDocument2;
doc.designMode = "On";
webBrowser1.Document.OpenNew(false).Write(#"<html><body><span>Project Title</span><input type=""text"" value="""" /></body></html>");
}
...assuming that a reference had been added to MSHTML.
The documentCompleted event accomplishes the same thing as the Application.DoEvents in my first code exmaple, so that could go either way.
I just tried this method:
webBrowser1.Navigate(#"javascript:document.body.contentEditable='true'; document.designMode='on'; void 0");
Elements can be dragged and deleted, you can also edit text with a double click.
Do any have any experience how this cold be done, if you look at the image im looking for a solution to programacly change the Name field to somehing else stored inn a variable from a other textbox.
i was thinking of using something like
private void button1_Click(object sender, EventArgs e)
{
var xBox = textbox1.value;
webBrowser1.Document.All.GetElementsByName("Name")[0].SetAttribute("Value", xBox);
}
but i dont know the name of the Textbox, and Sieble seems to be a java thing? so i cant see the source behind it? does anyone know how to solve this issue. im making a automate app to help at work for handeling over 100 cases a day. Instead of typing the names, im looking for a solution to populate by the click of a button.
I cant handel this by the sieble API because we dont have contorle of the Siebel develompent, and wold take years to get the Sieble department to implement somthing like this in to the GUI. so im making a desktop app that can handel the issue.
Sounds like you need to just search through the html (manually) until you find the names/ids of the fields you need to set.
Also, if the site supports Firefox, try using Firebug. In Firebug's inspect mode you can mouse over a text field and get the id of it.
My solution to this was using cordinates, and simulate keys klicks, im using Global Mouse and Keyboard Library for this, found at this location http://www.codeproject.com/KB/system/globalmousekeyboardlib.aspx
private void button1_Click(object sender, EventArgs e)
{
this.Location = new Point(0, 0);
inputBlocker();
xX = int.Parse(this.Location.X.ToString());
yY = int.Parse(this.Location.Y.ToString());
defaultMousePos();
//Thread.Sleep(600);
Cursor.Position = new Point(Cursor.Position.X + 1185, Cursor.Position.Y + 254);
//Thread.Sleep(600);
MouseSimulator.DoubleClick(MouseButton.Left);
KeyboardSimulator.KeyPress(Keys.T);
KeyboardSimulator.KeyPress(Keys.E);
KeyboardSimulator.KeyPress(Keys.S);
KeyboardSimulator.KeyPress(Keys.T);
KeyboardSimulator.KeyPress(Keys.O);
KeyboardSimulator.KeyPress(Keys.K);
KeyboardSimulator.KeyPress(Keys.Enter);
needUnblock = true;
inputBlocker();
}
#Darkmage - Is this a winforms application ?.If so did you not have any issues with loading the siebel activeX controls in the .NET webroswer control?