I am working with Winforms and I have a question about making these more dynamic. For instance I can create a winform that has a group of text boxes that displays data however how would I make this dynamic? In terms of the number of text boxes the user can see depends on what data is found?
I know I can do something along the lines of the below:
TextBox tb = new TextBox();
In my scenario I have an application that reads through a bunch of documents and if a $ is found then a prompt appears asking the user to input a proper value, however, if the document has a lot of values that need updating then this is a lot of dialog boxes. So a good way to resolve this is to have the dialog box appear at the end (after the file has been read) with all the values that need updating and the user can update all these at once.
The problem that I see is that the number of values that need to be displayed can be anything from 1 on wards, which means the loop would need to account for this.
My current code is as below;
foreach (FileInfo fi in rgFiles)
{
current++;
fileProcessBar.Value = current / count * 60 + 40;
string[] alllines = File.ReadAllLines(fi.FullName);
for (int i = 0; i < alllines.Length; i++)
{
if (alllines[i].Contains("$"))
{
// prompt
int dollarIndex = alllines[i].IndexOf("--");
Regex regex = new Regex(#"(--.{1,100})");
var chars = regex.Match(alllines[i]).ToString();
string PromptText = chars.Replace("-", "");
string promptValue = CreateInput.ShowDialog(PromptText, fi.FullName);
if (promptValue.Equals(""))
{
}
else
{
alllines[i] = alllines[i].Replace("$", promptValue);
File.WriteAllLines(fi.FullName, alllines.ToArray());
}
}
}
prompt method:
public static string ShowDialog(string text, string caption)
{
Form prompt = new Form()
{
Width = 600,
Height = 150,
FormBorderStyle = FormBorderStyle.FixedDialog,
Text = caption,
StartPosition = FormStartPosition.CenterScreen
};
Label textLabel = new Label() { Left = 50, Top = 15, Width = 500, Text = text };
TextBox textBox = new TextBox() { Left = 50, Top = 52, Width = 500 };
Button confirmation = new Button() { Text = "Add", Left = 450, Width = 100, Top = 72, DialogResult = DialogResult.OK };
confirmation.Click += (sender, e) => { prompt.Close(); };
prompt.Controls.Add(textBox);
prompt.Controls.Add(confirmation);
prompt.Controls.Add(textLabel);
prompt.AcceptButton = confirmation;
prompt.MaximizeBox = false;
return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";
}
My question is how can a winform be more dynamic as in terms of size and what is displayed? how can I create a new form without specifying size and position? but still not being a jumbled mess?
Make a new Form with a certain size. Then add a FlowLayoutPanel to the form which has almost the same width as the form and almost the same height. Leave enough space for the button that you need:
In the panel properties set the fields AutoSize to true and AutoSizeMode to GrowAndShrink:
Don't forget to specify the FlowDirection:
this.panel.FlowDirection = FlowDirection.TopDown;
Now you need just a method which adds your prompting controls to the controls of the FlowLayoutPanel (which will order them in an automatic fashion) :
public void AddToCanvas(string text)
{
this.flowLayoutPanel1.Controls.Add(new Label() {Text = text});
this.flowLayoutPanel1.Controls.Add(new TextBox());
Resize();
}
And a resize method to adjust the form to the amount of current controls inside it:
public void Resize()
{
Size s = new Size();
s.Height = this.flowLayoutPanel1.Height + this.button_Accept.Height +
(this.flowLayoutPanel1.Controls.Count * 10) + y_offset;
s.Width = this.flowLayoutPanel1.Width + 10;
this.MaximumSize = s;
this.Size = s;
}
With this input:
random text
$ Name
$ Address
random text
$ Age
random text
$ Planet
$ Continent
random text
$ StarSystem
I get the following Result:
EDIT:
Create a variable after you have read the contents of one file (before you loop through the lines):
DynamicPrompt dp = new DynamicPrompt("YourCaption");
for (int i = 0; i < alllines.Length; i++)
{
if (alllines[i].Contains("$"))
{
Start the loop and if you get to the important line call
dp.AddToCanvas(PromptText);
Related
I'm working on a personal project where I'm building a notes generator, and I have this TextBox dynamically created everytimes a button is clicked, it works fine just like how I expected but things gets weird when I tried to name each of these TextBox to different name by using a loop Name = "Note" + i where i is the loop variable.
So what I was expecting to happens is that each of the TextBox names to be something like Note1 Note2 Note3 ... but instead when I retrieved each of the TextBox name to a MessageBox in the same loop which is used to generates the TextBox, the MessageBox throws this: Note 1 Note 1 Note 1 ... instead when I clicked the button thrice.
int curr = 0;
private void guna2Button1_Click(object sender, EventArgs e) {
int top = 25;
int h_p = 170;
curr++;
for(int i=1; i<curr+1; i++) {
// Notes
var new_note = new Guna2TextBox() {
Text = "Title\n",
Name = "Note" + i,
Multiline = true,
AcceptsTab = true,
AcceptsReturn = true,
WordWrap = false,
ScrollBars = ScrollBars.Vertical,
Width = 220,
Height = 110,
BorderRadius = 8,
Font = new Font("Bahnschrift", 13),
ForeColor = Color.White,
FillColor = ColorTranslator.FromHtml("#1E1E1E"),
BorderColor = ColorTranslator.FromHtml("#2C2C2C"),
Location = new Point(450,top)
};
MessageBox.Show(i.ToString());
top += h_p;
flowLayoutPanel1.Controls.Add(new_note);
curr = 0;
}
}
The problem is caused by the fact that inside the loop you set always curr back to zero. And the loop is not needed at all because you want to add a textbox at each click. So you just need to look at the Count property of the FlowLayoutPanel and use that value to prepare the name.
Another problem to solve is how to position the next control inside the panel but again you could calculate easily with a the Count property
private void guna2Button1_Click(object sender, EventArgs e)
{
int nextTop = 25 + (flowLayoutPanel.Controls.Count * 170);
var new_note = new Guna2TextBox() {
Text = "Title\n",
Name = "Note" + flowLayoutPanel.Controls.Count + 1,
.....
Location = new Point(450,nextTop)
};
flowLayoutPanel1.Controls.Add(new_note);
}
I don't think you need to use the For loop in this case. You can just use the variable curr for each textboxes. So instead of the For loop, you can use this :
int top = 25;
int h_p = 170;
curr++;
var new_note = new Guna2TextBox() {
Text = "Title\n",
Name = "Note" + curr,
Multiline = true,
AcceptsTab = true,
AcceptsReturn = true,
WordWrap = false,
ScrollBars = ScrollBars.Vertical,
Width = 220,
Height = 110,
BorderRadius = 8,
Font = new Font("Bahnschrift", 13),
ForeColor = Color.White,
FillColor = ColorTranslator.FromHtml("#1E1E1E"),
BorderColor = ColorTranslator.FromHtml("#2C2C2C"),
Location = new Point(450,top)
top += h_p;
flowLayoutPanel1.Controls.Add(new_note);
};
I have been working a program that is used as a guide/way to memorize items when studying terms for whatever (test, exam, etc.). It generates a set amount of textboxes inside of a group box (which has the subject name set as its text property) in which you can write the term name and definition. I was wondering how I would save what was written in the text boxes after being generated. Perhaps being able to save the state of the application after pressing save and being able to set the application to its previous state when wanted (Kind of like snapshots that you use in virtual machines). Another way I thought of is to perhaps make a group of each subject somehow and within that store an array of text in each term name box and the associated term definition. Here is the code inside of the button I press to generate the text boxes. There is also a photo of the form: Photo of form Here is one of the program running: Image of Program running Edit: I am not asking for the straight up entire code. I would like just a guideline/idea of how I would go about doing this.
GroupBox groupBox1 = new GroupBox();
TextBox textTest = new TextBox();
textTest.Location = new Point(15, 40);
groupBox1.Controls.Add(textTest);
Button buttonForBoxes = new Button();
NumericUpDown numberUpDown1 = new NumericUpDown();
groupBox1.Controls.Add(buttonForBoxes);
buttonForBoxes.Location = new Point(140, 40);
buttonForBoxes.Text = "moretext";
numberUpDown1.Location = new Point(15, 15);
groupBox1.Controls.Add(numberUpDown1);
groupBox1.AutoSize = true;
var numVal = numericUpDown1.Value;
var numDo2 = 40;
var numDo1 = 120;
var inSubjectBox = subjectBox.Text;
//Makes boxes however many times you specify
for (int i = 0; i < numVal; i++)
{
numDo2 += 110;
TextBox text1 = new TextBox();
text1.Location = new Point(15, numDo1);
groupBox1.Controls.Add(text1);
numDo1 += 110;
TextBox textThing = new TextBox();
textThing.Location = new Point(15, numDo2);
textThing.Multiline = true;
textThing.Size = new System.Drawing.Size(600, 60);
groupBox1.Controls.Add(textThing);
}
// Set the Text and Dock properties of the GroupBox.
groupBox1.Text = inSubjectBox;
groupBox1.Dock = DockStyle.Top;
// Enable the GroupBox (which disables all its child controls)
groupBox1.Enabled = true;
// Add the Groupbox to the form.
this.Controls.Add(groupBox1);
Maybe you can try to save the textbox info into Settings.
First, go to Project -> Properties -> Settings and add new items(type of StringCollection) in Settings.
Then, modify the code like this(save the location of the TextBox in the format of "x;y"):
private void Addtextbox_Click(object sender, EventArgs e)
{
Properties.Settings.Default.text1Collection.Clear();
Properties.Settings.Default.textThingCollection.Clear();
var numVal = 2;
// code omitted
// ...
for (int i = 0; i < numVal; i++)
{
numDo2 += 110;
TextBox text1 = new TextBox();
text1.Location = new Point(15, numDo1);
groupBox1.Controls.Add(text1);
// save info to Settings
Properties.Settings.Default.text1Collection.Add(String.Format("{0};{1}", text1.Location.X, text1.Location.Y));
numDo1 += 110;
TextBox textThing = new TextBox();
textThing.Location = new Point(15, numDo2);
textThing.Multiline = true;
textThing.Size = new System.Drawing.Size(600, 60);
groupBox1.Controls.Add(textThing);
// save info to Settings
Properties.Settings.Default.textThingCollection.Add(String.Format("{0};{1}", textThing.Location.X, textThing.Location.Y));
// call Save()
Properties.Settings.Default.Save();
}
// code omitted
// ...
}
private void LoadtextboxFromSettings_Click(object sender, EventArgs e)
{
foreach (string text1str in Properties.Settings.Default.text1Collection)
{
TextBox text1 = new TextBox
{
Location = new Point(Convert.ToInt32(text1str.Split(';')[0]), Convert.ToInt32(text1str.Split(';')[1]))
};
groupBox1.Controls.Add(text1);
}
foreach (string textThingstr in Properties.Settings.Default.textThingCollection)
{
TextBox textThing = new TextBox
{
Multiline = true,
Location = new Point(Convert.ToInt32(textThingstr.Split(';')[0]), Convert.ToInt32(textThingstr.Split(';')[1])),
Size = new Size(600, 60)
};
groupBox1.Controls.Add(textThing);
}
}
Besides, if you get the exception System.NullReferenceException: 'Object reference not set to an instance of an object.', try to add a default value for each "setting".
Update:
The way to set Settings default value.
I used to do something similar when storing the positions of forms and the size of some controls on them. Then it was necessary for the application to open on restart in the same form as it was last used.
All forms and controls data I saved to XML file, when closing application. When then application has been started I read this XML file and set positions of forms and controls.
I'm using WinForms in VS15 with C#.
I'm dynamically adding TextBoxs and Labels to my Form based upon a user selected value in a ComboBox (essentially this looks up a value in a data collection which tells my UI what controls it needs).
When I attempt to generate the controls, the Labels appear and layout just fine, however, the TextBoxs are remarkable in there absence.
I've tried fidelling with the MaximumSize and MinimumSize properties to see if they could be messing with something but it doesn't seem to be making any difference.
The code I use for doing this is below (I know the use of the List<Pair<Label,TextBox>> is pretty unecessary but I find it helps readability):
private void GenerateControls(string formType)
{
string[] formParameters = engine.GetFormParameters(formType);
if (formParameters == null) return;
SplitterPanel panel = splitContainer.Panel1;
panel.Controls.Clear();
List<Pair<Label, TextBox>> controlPairs = new List<Pair<Label, TextBox>>();
int tabIndex = 0;
Point labelPoint = panel.Location + new Size(20, 20);
Size initialOffset = new Size(0, 30);
Size horizontalOffset = new Size(40, 0);
Size tBoxSize = new Size(40,20);
foreach (string parameter in formParameters)
{
Label label = new Label
{
Text = parameter,
Tag = "Parameter Label",
Name = $"lbl{parameter}",
Location = (labelPoint += initialOffset)
};
TextBox textBox = new TextBox
{
AcceptsTab = true,
TabIndex = tabIndex++,
Text = "",
Tag = parameter,
Name = $"txt{parameter}",
MaximumSize = tBoxSize,
MinimumSize = tBoxSize,
Size = tBoxSize,
Location = labelPoint + horizontalOffset
};
controlPairs.Add(new Pair<Label, TextBox>(label, textBox));
}
foreach (Pair<Label, TextBox> pair in controlPairs)
{
panel.Controls.Add(pair.First);
panel.Controls.Add(pair.Second);
}
}
I don't believe that my use of Point + Size is the issue as the Point class overrides the + operator like so:
Unfortunately for me the issue appears to be simply that the dX was not a big enough value to prevent the text boxes from being hidden under the labels, I forgot that labels don't have transparent backgrounds.
While I was at it: I've removed the redundant List<Pair<<>>; added support for dynamically adjusting TextBox location based on Label size; and split it out into two separate loops, so my code now looks as below and works just fine:
private void GenerateControls(string formType)
{
string[] formParameters = engine.GetFormParameters(formType);
if (formParameters == null) return;
SplitterPanel panel = splitContainer.Panel1;
panel.Controls.Clear();
int tabIndex = 0;
Point labelPoint = panel.Location + new Size(20, 20);
Size verticalOffset = new Size(0, 30);
Size tBoxSize = new Size(200,20);
int maxLabelLength = 0;
foreach (string parameter in formParameters)
{
Label label = new Label
{
Text = parameter,
Tag = "Parameter Label",
Name = $"lbl{parameter}",
Location = (labelPoint += verticalOffset),
AutoSize = true
};
panel.Controls.Add(label);
if (label.Size.Width > maxLabelLength)
{
maxLabelLength = label.Size.Width;
}
}
Size horizontalOffset = new Size(maxLabelLength + 30, 0);
labelPoint = panel.Location + new Size(20, 20) + horizontalOffset;
foreach (string parameter in formParameters)
{
TextBox textBox = new TextBox
{
AcceptsTab = true,
TabIndex = tabIndex++,
Text = "",
Tag = parameter,
Name = $"txt{parameter}",
MaximumSize = tBoxSize,
MinimumSize = tBoxSize,
Size = tBoxSize,
Location = labelPoint += verticalOffset
};
panel.Controls.Add(textBox);
}
}
Thanks everyone who helped!
I'm currently designing a WinForms music player and I'm having some trouble figuring out how to set what a button does when the button is created via
Controls.Add(new Button(){})
The code I'm currently using is a while loop inside of which is the code to create a button name + x where x is a value that increments at the end of the loop. What i would like to do is set it so that on click the button will execute the function to play music which is named say "mpPlay". What would be the best way to go about this?
Here is the current code I'm using:
while (trackNoReader.Read())
{
flpTrackNo.Controls.Add(new Button()
{
Name = "btnTrackNo" + x,
Text = trackNoReader[0] as string,
BackColor = Color.Transparent,
FlatStyle = FlatStyle.Flat,
AutoSize = false,
Dock = DockStyle.Top,
Width = flpArtist.Width,
ForeColor = ColorTranslator.FromHtml("#444444"),
Font = new Font("Trebuchet MS", 9),
Enabled = true,
TextAlign = ContentAlignment.MiddleLeft,
FlatAppearance =
{
BorderSize = 0
},
});
x++;
}
If you wish to see the source code you can download the git repository here. Many Thanks - Ross
[EDIT]
Here's the code for mpPlay()
public void mpPlay(int x, string Column)
{
MySqlCommand selectPath = new MySqlCommand("SELECT" + Column + "FROM Music WHERE TrackNo=" + x);
selectPath.Connection = DB.connect;
MySqlDataReader readerPath = selectPath.ExecuteReader();
while (readerPath.Read())
{
path = readerPath[0] as string;
path = path.Replace("\"", "\\");
}
mpPlayer.Open(path);
mpPlayer.Play();
}
You could have a simple helper method like this:
public Button AttachMethodToButton(Button b, Action buttonMethod)
{
b.Click += (s, e) => buttonMethod();
return b;
}
which you would call like this:
flpTrackNo.Controls.Add(AttachMethodToButton(new Button()
{
// ... button properties like you already have
},
mpPlay)); // I'm assuming 'mpPlay' is a void method
If you want to call mpPlay with arguments, you'd call it like this:
flpTrackNo.Controls.Add(AttachMethodToButton(new Button()
{
// ... button properties like you already have
},
() => mpPlay(intParam, stringParam))); // replace intParam and stringParam with whatever arguments you want here
while (trackNoReader.Read())
{
flpTrackNo.Controls.Add(new Button()
{
Name = "btnTrackNo" + x,
Text = trackNoReader[0] as string,
BackColor = Color.Transparent,
FlatStyle = FlatStyle.Flat,
AutoSize = false,
Dock = DockStyle.Top,
Width = flpArtist.Width,
ForeColor = ColorTranslator.FromHtml("#444444"),
Font = new Font("Trebuchet MS", 9),
Enabled = true,
TextAlign = ContentAlignment.MiddleLeft,
FlatAppearance =
{
BorderSize = 0
},
});
// Adds Click event handler to last added button
flpTrackNo.Controls[flpTrackNo.Controls.Count - 1].Click += (sender, args) =>
{
// Call the function to play a sound
// Additionally the sender gives you the specific button as object
};
x++;
}
I'm looking to implement a Visual Studio-style undo drop-down button:
I've looked all over the internet, and can't seem to find any real implementations of this.
I've started by deriving from ToolStripSplitButton, but don't really know where to go from there. Its DropDown property is a ToolStripDropDown, but that doesn't seem to have anything regarding multiple items being selected, much less scrolling, and the text at the bottom.
So instead of the default ToolStripDropDown, I'm thinking maybe the whole drop down part should be a custom control, based on a combobox. The question then, is how to cause the right-side (drop down arrow) button to do something other than show its default drop down?
Am I on the right track here? Thanks!
Yes, I think you're on the right track. And in this case, ToolStripControlHost is your friend.
You don't necessarily need to derive from it (unless you are making your own control), but try just subscribing to the ToolStripSplitButton's DropDownOpening event:
Working example:
private ListBox listBox1;
public Form1()
{
InitializeComponent();
listBox1 = new ListBox();
listBox1.IntegralHeight = false;
listBox1.MinimumSize = new Size(120, 120); \\ <- important
listBox1.Items.Add("Item 1");
listBox1.Items.Add("Item 2");
}
private void toolStripSplitButton1_DropDownOpening(object sender, EventArgs e) {
ToolStripControlHost toolHost = new ToolStripControlHost(listBox1);
toolHost.Size = new Size(120, 120);
toolHost.Margin = new Padding(0);
ToolStripDropDown toolDrop = new ToolStripDropDown();
toolDrop.Padding = new Padding(0);
toolDrop.Items.Add(toolHost);
toolDrop.Show(this, new Point(toolStripSplitButton1.Bounds.Left,
toolStripSplitButton1.Bounds.Bottom));
}
Here is the result:
For your application, you would need to replace the ListBox with your own UserControl, so you can contain whatever your want in it. The ToolStripControlHost can only hold one control, and it's important to set the MinimumSize property, or else the dropped control isn't sized correctly.
Extra thanks to LarsTech! (I didn't know about ToolStripControlHost a few hours ago)
Here is my implementation, which is really close to the VS drop down...
You should be able to just drop this delegate & function into your Form:
public delegate void UndoRedoCallback(int count);
private void DrawDropDown(ToolStripSplitButton button, string action, IEnumerable<string> commands, UndoRedoCallback callback)
{
int width = 277;
int listHeight = 181;
int textHeight = 29;
Panel panel = new Panel()
{
Size = new Size(width, textHeight + listHeight),
Padding = new Padding(0),
Margin = new Padding(0),
BorderStyle = BorderStyle.FixedSingle,
};
Label label = new Label()
{
Size = new Size(width, textHeight),
Location = new Point(1, listHeight - 2),
TextAlign = ContentAlignment.MiddleCenter,
Text = String.Format("{0} 1 Action", action),
Padding = new Padding(0),
Margin = new Padding(0),
};
ListBox list = new ListBox()
{
Size = new Size(width, listHeight),
Location = new Point(1,1),
SelectionMode = SelectionMode.MultiSimple,
ScrollAlwaysVisible = true,
Padding = new Padding(0),
Margin = new Padding(0),
BorderStyle = BorderStyle.None,
Font = new Font(panel.Font.FontFamily, 9),
};
foreach (var item in commands) { list.Items.Add(item); }
if (list.Items.Count == 0) return;
list.SelectedIndex = 0;
ToolStripControlHost toolHost = new ToolStripControlHost(panel)
{
Size = panel.Size,
Margin = new Padding(0),
};
ToolStripDropDown toolDrop = new ToolStripDropDown()
{
Padding = new Padding(0),
};
toolDrop.Items.Add(toolHost);
panel.Controls.Add(list);
panel.Controls.Add(label);
toolDrop.Show(this, new Point(button.Bounds.Left + button.Owner.Left, button.Bounds.Bottom + button.Owner.Top));
// *Note: These will be "up values" that will exist beyond the scope of this function
int index = 1;
int lastIndex = 1;
list.Click += (sender, e) => { toolDrop.Close(); callback(index); };
list.MouseMove += (sender, e) =>
{
index = Math.Max(1, list.IndexFromPoint(e.Location) + 1);
if (lastIndex != index)
{
int topIndex = Math.Max(0, Math.Min(list.TopIndex + e.Delta, list.Items.Count - 1));
list.BeginUpdate();
list.ClearSelected();
for (int i = 0; i < index; ++i) { list.SelectedIndex = i; }
label.Text = String.Format("{0} {1} Action{2}", action, index, index == 1 ? "" : "s");
lastIndex = index;
list.EndUpdate();
list.TopIndex = topIndex;
}
};
list.Focus();
}
You can set it up and test like this, assuming you have a blank form (Form1) with a toolStrip that has 1 ToolStripSplitButton (toolStripSplitButton1) added:
public Form1()
{
InitializeComponent();
// Call DrawDropDown with:
// The clicked ToolStripSplitButton
// "Undo" as the action
// TestDropDown for the enumerable string source for the list box
// UndoCommands for the click callback
toolStripSplitButton1.DropDownOpening += (sender, e) => { DrawDropDown(
toolStripSplitButton1,
"Undo",
TestDropDown,
UndoCommands
); };
}
private IEnumerable<string> TestDropDown
{
// Provides a list of strings for testing the drop down
get { for (int i = 1; i < 1000; ++i) { yield return "test " + i; } }
}
private void UndoCommands(int count)
{
// Do something with the count when an action is clicked
Console.WriteLine("Undo: {0}", count);
}
Here is a better example using the Undo/Redo system from: http://www.codeproject.com/KB/cs/AutomatingUndoRedo.aspx
public Form1()
{
InitializeComponent();
// Call DrawDropDown with:
// The Undo ToolStripSplitButton button on the Standard tool strip
// "Undo" as the action name
// The list of UndoCommands from the UndoRedoManager
// The Undo method of the UndoRedoManager
m_TSSB_Standard_Undo.DropDownOpening += (sender, e) => { DrawDropDown(
m_TSSB_Standard_Undo,
"Undo",
UndoRedoManager.UndoCommands,
UndoRedoManager.Undo
); };
}
*Note: I did modify the Undo & Redo methods in the UndoRedoManager to accept a count:
// Based on code by Siarhei Arkhipenka (Sergey Arhipenko) (http://www.codeproject.com/KB/cs/AutomatingUndoRedo.aspx)
public static void Undo(int count)
{
AssertNoCommand();
if (CanUndo == false) return;
for (int i = 0; (i < count) && CanUndo; ++i)
{
Command command = history[currentPosition--];
foreach (IUndoRedo member in command.Keys)
{
member.OnUndo(command[member]);
}
}
OnCommandDone(CommandDoneType.Undo);
}
I'd suggest implementing the popup separately from the toolbar button. Popups are separate windows with a topmost-flag which auto-close when losing focus or pressing escape. If you code your own popup window that frees you from having to fit your behaviour to a preexisting model (which is going to be hard in your case). Just make a new topmost window with a listbox and status bar, then you are free to implement the selection behavior on the listbox like you need it.
Vs 2010 is a WPF application. If you are in the beginning of this application development than use WPF as a core technology. WPF drop down button is implemented in WPF ribbon. Source code is available on CodePlex.