How to show output in webapp directlt at form1 C# - c#

I want to print values at bottom of Form1 directly. It is a web app so if I
write Console.WriteLine("Something"); it doesn't make sense or doesn't print out any thing at Form1. How can I print in Form1 directly?

Here's a pictorial sequence for printing the word "Something" on a web form (on your browser):
Right-click on the blue highlighted WebApplication2.
A webform will appear:
Press F7 key to go to the webform code page.
Then look at your resulting browser page.
UPDATE:
Oh, so you want to write to a winform instead of a webform. Use this code:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
label1.Text = "Something";
}
}
}
Then,
Put your mouse on label1, right-click, choose "View Designer".
In the properties box, go to the "Text" property.
To the right of the property, type "Click here" to replace "Label1".
Hit return.
Then run it.

I assume you are using a ASP.NET Web Forms and want to add controls directly to the HTML via code behind.
Look into UserControls for a more proper way moving forward. https://msdn.microsoft.com/en-us/library/y6wb1a0e.aspx
But to answer your question directly, the quick and dirty is below.
Within the aspx file create a PlaceHolder
<asp:PlaceHolder ID="phMain" runat="server"></asp:PlaceHolder>
In the code behind you can add HTML directly to the PlaceHolder
phMain.Controls.Add(new LiteralControl("<span>Hello!</span>"));
Update
I see you added a picture of a WinForm app after you said Web App. In that case you should try a ListView https://msdn.microsoft.com/en-us/library/system.windows.forms.listview(v=vs.110).aspx

Related

How to create a output log window similar to visual studio log window

I need to add an output window to my windows form, similar to the output window in visual studio.
What i have done is created a list box and planning to log the details as and when they arrive. I dont know how to add the highlighted button controls (close, windows position, autohide). I am completely new to visual studio, winforms, c#. Just exploring various things to draft an application. I would be nice if anyone could suggest ideas in adding those controls.
And also please suggest if there is an alternative to list box to display the output window.
You can use SplitContainer and add Textbox or RichTextbox as output window you want. You can then append output text to the text property of Textbox ot RichTextbox. Instead of highlighted controls, you can change the size of SplitContainer at run time, or hide one of the section using menu option.
~Nilesh
Based on Sam W 's comment, Using DockPanel would create a another window inside the winform, similar to output, error window in Visual Studio IDE.
dockpanelsuite.com
This site provides amazing Docking Features http://docs.dockpanelsuite.com/ provides steps to install them.
In Form 1, set isMidiContainer = true in Form1's Properties and drag the DockPanel from toolBox(after installing and following steps in that page).
create a form2 and add the following
using WeifenLuo.WinFormsUI.Docking;
namespace Forms
{
public partial class Form2 : DockContent
{
public Form2()
{
InitializeComponent();
}
}
}
In Form1 add
public Form1()
{
InitializeComponent();
Form2 f2 = new Form2();
f2.Show(dockPanel, DockState.DockBottom);
}
We can add many more forms and dock them to one parent form.

"Include" instead of ShowDialog()

I'm trying to make a WindowsFormApplication in Visual Studio 2015 and need some help.
I've been trying to search for the answer on internet but can find out how to do the following:
I have two windows (solutions?). I open the second window with a button in the first one with this code:
this.Hide();
intermec prodinter = new intermec();
prodinter.ShowDialog();
My question is:
How can i "include" the second window (like "include" in PHP) instead of close the first window and then open the next one, like it does now?
A Form is just another Control. Think of it as a Container (because it holds other Controls).
A User Control can also hold more than one Control. There are ways you can display a Window inside another Window in a WinForms app, but the desired effect is not always guaranteed. So it would be best to place all of your controls (for "page 1", for example) in a User Control called "Page1", and then, when appropriate, add that User Control to the Form, and set its Dock property to Fill.
And when it's time to show a different "page", Hide(); "Page1", and Show(); "Page2".
I think you are talking about form inheritance:
Just create a form, lets call it as frmBase. And add some controls onto frmBase which you want to have on other forms as well.
Create other form, lets call it as frmDerived.
In the code behind of frmDerived, just do the following:
// derive the frmDerived form from frmBase
public partial class frmDerived : frmBase
{
public frmDerived()
{
InitializeComponent();
}
}
And then just check the frmDerived form design, it should include everything from frmBase.
And you may want to make the access modifier of some controls of frmBase to Public as required to access them on frmDerived.
I hope this will help you. :)

Making a button open a hyperlink

I've just started with Xamarin and C# to do some iOS development. I'm trying to make a button open a web page in Safari. I have added the button in the XCode visual editor and dragged the button into the code view to start using it in Xamarin.
I'm getting the same problem as this although I can't put the code in the view as the answer suggests I should as I need access to UIApplication to open the web page in Safari.
Here is my code:
Login.cs:
partial void webLink (MonoTouch.Foundation.NSObject sender)
{
UIApplication.SharedApplication.OpenUrl(new NSUrl("http://www.google.com/"));
}
And the error:
A partial method implementation is missing a partial method declaration
I suppose you added a UIButton in Xcode and then you also dragged the newly created UIButton to Assistant editor and named your instance e.g. btnOpenGoogle.
Next you need to implement the TouchUpInside event handler in ViewDidLoad:
btnOpenGoogle.TouchUpInside += HandleBtnOpenGoogleTouchUpInside;
And somewhere in your code create the HandleBtnOpenGoogleTouchUpInside method:
private void HandleBtnOpenGoogleTouchUpInside(object sender, EventArgs e)
{
UIApplication.SharedApplication.OpenUrl(new NSUrl("www.google.com"));
}
Hope this helps.
Just use an IBAction,
- (IBAction)ButtonName:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com/"]];
}
Just replace the 'ButtonName' with the name of your existing button, and then connect everything to the files owner in the storyboard.
Shouldn't that be
private/public void webLink (MonoTouch.Foundation.NSObject sender)
instead of
partial void webLink (MonoTouch.Foundation.NSObject sender) ?
I don't think you should have partial.

Puzzle. WPF host in winform - bug with string containing "_"

Hosting WPF in winform is explained here Walkthrough: Hosting a WPF Composite Control in Windows Forms. I explain the problem in the most simple way: just create a winform project. Then I create another project WPF User Control Library. On User control library I add one button and name it button1. Then in xaml.cs file i create one public function which looks like this:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public void SetText(string text)
{
button1.Content = text;
}
}
I add that project as a reference in winform so I can add control to my winform. In winform I add one button and create button onClick event. The code looks like this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
wpfButton.SetText("asd 12_2_a_s");
}
}
And now the party begins. I compile the project and the final looks like that:
So if I click on left button, on right button there should show string looks like this: "asd 12_2_a_s". But, what is happening is always first "_" is missing. That I get this:
The primitive solution that problem is just to write doubles "__" wpfButton.SetText("asd 12__2__a__s");
And that works. But my question is: Is this is actual bug or I missing something?
The underscore in the text/content of a control is a character used to indicate the access key. You can escape it by using a double underscore __
"t__est"
Haven't tested this, but you also could use the # sign. #"t_est" will output t_est
EDIT: # Doesn't work for setting Text/Content Properties.

Desktop applications dynamic GUI problem

I have asked the question "Is there something like master page in desktop applications?" Now I am in position that I have to extend the question. Thanks for understanding.
I have add one MDI master form into my project and several inherited forms that inherit MDI master one. I was using this code.
private void searchToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (Form child in this.MdiChildren)
{
child.Close();
}
Search childSearchForm = new Search();
childSearchForm.MdiParent = this;
childSearchForm.Text = "Search ";
childSearchForm.Show();
}
This code is triggered when I press some button on master form and the new in this case Search form is opened inside master.
Now my question is the right way to build desktop applications or there is some other more elegant way where content of user interface can be dynamic and switch from view to view by clicking on the buttons inside. For instance clicking on "Search" button on some search form will take you to search results grid, all that happening in one master form.
And if this is right way (which I doubt) how can I achieve to open other inside forms by clicking on buttons inside them. Also if I put some controls on masterpage they will appear two times in master form and in inherited form.
Thanks.
PS
I am using Visual Studio 2008 and MS SQL 2005.
If you are only wanting to show one view at a time you could create a new user control for each view you require. e.g One for your search results.
Then you could add a panel and clear the controls contained within the panel and add the new one to display the view you are after.
Or as described, the other option is to use a tab control, hide the tabs and set the visible index programatically.
Not sure how you would easily do this in winforms, but in WPF you could create a navigation app - a link driven navigation similar to a web browser experience but still a stand alone application. See http://msdn.microsoft.com/en-us/rampup/cc514215.aspx for details of how to get started.

Categories

Resources