Re: Example of nested layout panels and dynamic form creation with .NET

  • From: "Ricks Place" <OFBGMail@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sat, 11 Oct 2008 06:11:58 -0400

Hi guys:
I like the visual studio features as well. Wish I could use Intellisense it would save huge blocks of time but I've not figured out how to use it so just shut it off. I can't imagine creating all my controls and DataSets by hand anymore. And a DataSet is quite a complex object with thousands of lines of code. I don't know about linq or other things but the IDE servs many useful purposes for faster coding. I especially like working in VWD since layout is drag and drop but all the code is there in the html editor for manual tweaking. The complex controls are also pre defined which makes life easier and again, in VWD, the html is available for tweaking.
Rick USA
Rick USA
----- Original Message ----- From: "James Panes" <jimpanes@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Saturday, October 11, 2008 4:54 AM
Subject: Re: Example of nested layout panels and dynamic form creation with .NET


Hi Teddy,

I had been out of the loop for several years when I started programming with
Bill Dennis's Blind Geeks. The VS interface was like very easy to use. It
helped me a lot especially when it came to intellesense and form layout.

How would you like to go back to "Edlin" and a paper manual?

Sorry if you don't like exactly what it does, but I will not agree that it
is useless.

.
Regards,
James
jimpanes@xxxxxxxxx
jimpanes@xxxxxxxxxxxx
"Everything is easy when you know how."

----- Original Message ----- From: "Octavian Rasnita" <orasnita@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Friday, October 10, 2008 4:55 PM
Subject: Re: Example of nested layout panels and dynamic form creation with
.NET


Aha, so I am not wrong when I say that actually, VS.net is pretty useless
for the blind?

Again, if we don't consider Intelisense, of course.

Octavian

----- Original Message ----- From: "Jamal Mazrui" <empower@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Friday, October 10, 2008 11:26 PM
Subject: Example of nested layout panels and dynamic form creation with .NET


/*
Example of nested layout panels and dynamic form creation
Public domain by Jamal Mazrui
October 10, 2008

Here is an example of using nested layout panels of the .NET Framework.
Note that no pixel coordinates are used for positioning and sizing
controls.  The form, TableLayoutPanel, FlowLayoutPanels, and Buttons are
all laid out  automatically according to defaults and need.

I wrote and compiled this C# code with EdSharp and the command-line
compiler.  Although Visual Studio certainly has its benefits, I think
significantly more time, effort, and code would probably be involved to do
the same thing with the form designer, code generator, and multiple files
of a Visual Studio project.

Below is the source code of LayoutPanels.cs, which is also included with
the compiled version, LayoutPanels.exe in the archive available at
http://EmpowermentZone.com/LayoutPanels.zip

When the executable is run, it calls a function called MultiInput that I
have found useful in various contexts. It presents a dialog with a number
of edit boxes determined at runtime.  Parameters to the function provide
the dialog title as a string, and the labels and default values of each
field in arrays.  The function returns an array with values as edited by
the user, or an empty array if the dialog is canceled.  The program shows
those return values in a message box.
*/

using System;
using System.Collections.Generic;
using System.Windows.Forms;

class Program {
static void Main() {
string sTitle = "Example of Layout Panels";
string[] aLabels = {"Label1", "Label2", "Label3"};
string[] aValues = {"Value1", "Value2", "Value3"};

string[] aResults = MultiInput(sTitle, aLabels, aValues);
if (aResults.Length == 0) return;

MessageBox.Show(String.Join("\n", aResults), "Results");
Console.Write(String.Join("\n", aResults));
} // Main method

public static string[] MultiInput(string sTitle, string[] aLabels,
string[] aValues) {

/*
Define a dialog form containing a vertical FlowLayoutPanel, which in turn,
contains a TableLayoutPanel and a horizontal FlowLayoutPanel below it
After initializing each control, suspend automatic layout until all its
properties, and those of its child controls, have been set
The OK button captures the values entered or modified, which the function
returns in an array
*/

// Define the dialog form
Form frm = new Form();
frm.SuspendLayout();
frm.AutoSize = true;
frm.AutoSizeMode = AutoSizeMode.GrowAndShrink;
frm.AutoScroll = true;

// Define the main , vertical FlowLayoutPanel
FlowLayoutPanel flpMain = new FlowLayoutPanel();
flpMain.SuspendLayout();
flpMain.AutoSize = true;
flpMain.AutoSizeMode = AutoSizeMode.GrowAndShrink;
flpMain.FlowDirection = FlowDirection.TopDown;

/*
Define a TableLayoutPanel with two colums, the left containing field
labels and the right containing field values
The number of rows is the number of items in the array of field labels
passed to the function.
There will be one row for each field.
determined by the size*/

TableLayoutPanel tlpFields = new TableLayoutPanel();
tlpFields.SuspendLayout();
tlpFields.Anchor = AnchorStyles.None;
tlpFields.AutoSize = true;
tlpFields.AutoSizeMode = AutoSizeMode.GrowAndShrink;
tlpFields.ColumnCount = 2;

// Add a column style for each column
for (int i = 0; i < tlpFields.ColumnCount; i++) {
tlpFields.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
}

// Add a row and row style for each field
tlpFields.RowCount = aLabels.Length;
for (int i = 0; i < tlpFields.RowCount; i++) {
Label lbl = new Label();
lbl.AutoSize = true;
lbl.Text = aLabels[i] + ":";
TextBox txt = new TextBox();
txt.Text = aValues[i];
tlpFields.Controls.AddRange(new Control[] {lbl, txt});
tlpFields.RowStyles.Add(new RowStyle(SizeType.AutoSize));
}
tlpFields.ResumeLayout();

// Below the TableLayoutPanel of fields, add a horizontal FlowLayoutPanel
containing buttons
FlowLayoutPanel flpButtons = new FlowLayoutPanel();
flpButtons.SuspendLayout();
flpButtons.Anchor = AnchorStyles.None;
flpButtons.AutoSize = true;
flpButtons.AutoSizeMode = AutoSizeMode.GrowAndShrink;
flpButtons.FlowDirection = FlowDirection.LeftToRight;

// Define the OK button
Button btnOK = new Button();
btnOK.Text = "OK";

// Define its event handler
List<string> listResults = new List<string>();
btnOK.Click += delegate(object o, EventArgs e) {
foreach (Control ctl in tlpFields.Controls) {
if (ctl.GetType() == typeof(TextBox)) listResults.Add(ctl.Text);
}
frm.Close();
};

// Define the Cancel button
Button btnCancel = new Button();
btnCancel.Text = "Cancel";
btnCancel.Click += delegate(object o, EventArgs e) {frm.Close();};

flpButtons.Controls.AddRange(new Control[] {btnOK, btnCancel});
flpButtons.ResumeLayout();

flpMain.Controls.AddRange(new Control[] {tlpFields, flpButtons});
flpMain.ResumeLayout();

// Set remaining properties of the form
frm.AcceptButton = btnOK;
frm.CancelButton = btnCancel;
frm.StartPosition = FormStartPosition.CenterParent;
frm.Text = sTitle;
frm.Controls.Add(flpMain);
frm.ResumeLayout();
frm.ShowDialog();
frm.Dispose();

return listResults.ToArray();
} // MultiInput method

} // Program class

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: