本文整理汇总了C#中Control.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Control.Add方法的具体用法?C# Control.Add怎么用?C# Control.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Control
的用法示例。
在下文中一共展示了Control.Add方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CollapsePanel
public CollapsePanel(Manager manager, Control parent, string Name, int expandedHeight = 100, bool extended = true)
{
this.panel = new GroupPanel(manager);
panel.Init();
panel.Height = expandedHeight;
panel.Width = parent.Width - 20;
panel.Resizable = true;
//panel.Text = " " + Name.Trim();
Text = Name;
this.collapseButton = new Button(manager);
collapseButton.Init();
collapseButton.Width = 15;
collapseButton.Height = 18;
collapseButton.Text = "^";
collapseButton.Click += collapseButton_Click;
this.ExpandedHeight = expandedHeight;
this.panelControls = new Dictionary<string, Control>();
this.parent = parent;
parent.Add(panel);
parent.Add(collapseButton);
this.IsExtended = extended;
parent.Refresh();
}
示例2: AddInformation
public override int AddInformation(Manager manager, Player player, Control control, int yPos)
{
var currentHouse = player.House;
const int spacing = 20;
int xPos = spacing;
if (currentHouse == null) {
var noHouseLabel = new Label(manager) { Text = "You have no house to sell!", Width = 400, Left = xPos, Top = yPos, Name = IgnoreString };
noHouseLabel.Init();
control.Add(noHouseLabel);
} else {
var houseGraphic = manager.Game.Content.Load<Texture2D>(currentHouse.HouseGraphic);
yPos += 20;
// Put the house graphic into an image box
var imageBox = new ImageBox(manager) {
Left = 16,
Top = yPos,
Image = houseGraphic,
Color = Color.White,
Width = houseGraphic.Width,
Height = houseGraphic.Height,
Name = IgnoreString,
Parent = control
};
imageBox.Init();
var descriptionText = new Label(manager) {
Text =
String.Format(
"Name : {0}\n\n" +
"Average Value: ${1:N0}\n\n" +
"Current Value: ${2:N0}\n\n" +
"Bought for : ${3:N0}\n\n" +
"Total profit :: ${4:N0}",
currentHouse.Name, currentHouse.InitialValue, currentHouse.Value, currentHouse.PlayerBuyingValue, currentHouse.PlayerBuyingValue - currentHouse.Value),
Top = yPos,
Left = imageBox.Width + 60,
Height = 130,
Width = 200,
Parent = control,
Name = IgnoreString
};
yPos += imageBox.Height + 20;
var sellHouseButton = new Button(manager) {
Text =
"Sell House",
Width = 400, Left = xPos, Top = yPos,
Name = IgnoreString
};
sellHouseButton.Click += (sender, args) => {
_houseCallback(player, currentHouse);
PopulateTab(manager, player, control);
};
sellHouseButton.Init();
control.Add(sellHouseButton);
}
return yPos;
}
示例3: RoomPanel
public RoomPanel(Sidebar sidebar, Control parent, Room room, bool interactive, int Top = 0, int Padding = 5)
{
this.Padding = Padding;
panel = new Panel(sidebar.manager);
panel.Init();
panel.Top = Top;
panel.Left = Padding;
panel.Width = room.worldWidth;
panel.Height = room.worldHeight;
//roomPanel.Left = (parent.Width - roomPanel.Width)/2;
int col = 30;
panel.Color = new Color(col, col, col);
panel.BevelBorder = BevelBorder.All;
panel.BevelStyle = BevelStyle.Flat;
panel.BevelColor = Color.Black;
parent.Add(panel);
panel.ClientArea.Draw += (s, e) =>
{
e.Renderer.Draw(room.roomRenderTarget, e.Rectangle, Color.White);
};
refreshAction = refresh;
parent.VisibleChanged += (s, e) => {
if (parent.Visible)
OrbIt.OnUpdate += refreshAction;
else
OrbIt.OnUpdate -= refreshAction;
};
panel.Click += (s, e) =>
{
Point innerpos = (e as MouseEventArgs).Position;
//room.spawnNode(innerpos.X, innerpos.Y);
Utils.notImplementedException();
};
}
示例4: Main
static void Main(string[] args)
{
while (true)
{
Control data = new Control();
System.Console.WriteLine(">> FileSystem TEST");
System.Console.WriteLine();
System.Console.WriteLine("1. Open / Create File");
System.Console.WriteLine("2. Add Element");
System.Console.WriteLine("3. Update Element");
System.Console.WriteLine("4. Remove Element");
System.Console.WriteLine("5. Search Element");
System.Console.WriteLine("6. Print List");
System.Console.WriteLine();
System.Console.WriteLine("0. Close / Quit Program");
System.Console.WriteLine();
System.Console.Write("Select Number : ");
// select menu
Select? sel = null;
try
{
sel = (Select)int.Parse(System.Console.ReadLine());
}
catch (Exception e) { }
System.Console.WriteLine();
switch (sel)
{
case Select.Open: data.Open(); break;
case Select.Add: data.Add(); break;
case Select.Update: data.Update(); break;
case Select.Remove: data.Remove(); break;
case Select.Search: data.Search(); break;
case Select.List: data.List(); break;
case Select.Close: return;
default:
System.Console.WriteLine(">> Plz input Number (0~6)\n");break;
}
}
}
示例5: Show
public void Show(Control.ControlCollection parent)
{
this.Dock = DockStyle.Fill;
parent.Add(this);
}
示例6: OfferToSellHouse
private void OfferToSellHouse(GameInfo gameInfo, IGameState waitState)
{
var currentHouse = gameInfo.CurrentPlayer.House;
var houseGraphic = gameInfo.Content.Load<Texture2D>(currentHouse.HouseGraphic);
var manager = gameInfo.Manager;
var container = new Control(manager) { Left = 16, Top = 16, Color = Color.Transparent };
var firstLine = new Label(manager) { Text = "You have been offered to buy a new house! \nYou must sell your current house to be able to buy this one. \n\n Current House:", Width = 400, Height = 60};
container.Add(firstLine);
// Put the house graphic into an image box
var imageBox = new ImageBox(manager)
{
Left = 16,
Top = 60,
Image = houseGraphic,
Color = Color.White,
Width = houseGraphic.Width,
Height = houseGraphic.Height
};
imageBox.Init();
container.Add(imageBox);
var descriptionText = new Label(manager)
{
Text =
String.Format(
"Name : {0}\n\n" +
"Average Value: ${1:N0}" +
"\n\nCurrent Value: ${2:N0}\n\n",
currentHouse.Name, currentHouse.InitialValue, currentHouse.Value),
Top = imageBox.Height / 2,
Left = imageBox.Width + 60,
Height = 100,
Width = 200
};
container.Add(descriptionText);
var newHouse = new Label(gameInfo.Manager)
{Text = " New offered house", Width = 150, Parent = container, Top = 200, Left = 16};
newHouse.Init();
var imageBox2 = new ImageBox(manager)
{
Left = 16,
Top = 230,
Image = gameInfo.Content.Load<Texture2D>(House.HouseGraphic),
Color = Color.White,
Width = houseGraphic.Width,
Height = houseGraphic.Height
};
imageBox.Init();
container.Add(imageBox2);
var descriptionText2 = new Label(manager)
{
Text =
String.Format(
"Name : {0}\n\n" +
"Average Value: ${1:N0}" +
"\n\nCurrent Value: ${2:N0}\n\n",
House.Name, House.InitialValue, House.Value),
Top = imageBox.Height*4 / 2,
Left = imageBox2.Width + 60,
Height = 100,
Width = 200
};
container.Add(descriptionText2);
var offerHouseLine = new Label(manager) { Text = "Would you like to sell your current house?", Width = 400, Top = imageBox.Height*2 + 140 };
container.Add(offerHouseLine);
container.Width = descriptionText.Left + descriptionText.Width + 16;
container.Height = offerHouseLine.Top + offerHouseLine.Height;
//"Would you like to buy this house? \n" + House.Name, "\nDo you want to buy a house""
var confirmWindow = new ConfirmWindow(manager, String.Empty, title: "Do you want to sell your house?", control: container);
confirmWindow.AffirmButton.Click += (sender, args) => SellCurrentHouse(confirmWindow, gameInfo, waitState);
confirmWindow.DenyButton.Click += (sender, args) => CloseWindow(confirmWindow, gameInfo, waitState);
}
示例7: InitializeControls
protected void InitializeControls(Control parent, int top)
{
foreach (Label label in LabelsToShow)
{
parent.Add(label);
}
for (int i = 0; i < LabelsToShow.Count; i++)
{
Label label = LabelsToShow[i];
label.Left = 4;
label.Width = label.Parent.Width - 4;
if (i == 0)
label.Top = top;
else
{
label.Top = LabelsToShow[i - 1].Top + LabelsToShow[i - 1].Height + 2;
}
if (label is RappingLabel)
{
label.Height = label.Parent.Height - label.Top - 4;
label.Alignment = Alignment.TopLeft;
label.TextColor = Microsoft.Xna.Framework.Color.LightGray;
(label as RappingLabel).WrapText();
}
}
}
示例8: Init
public void Init(Control parent, Manager manager)
{
switch (Type)
{
case "Container":
Container container = new Container(manager);
container.Init();
SetProperties(container, parent, manager);
container.AutoScroll = true;
break;
case "ImageBox":
ImageBox box = new ImageBox(manager);
box.Init();
SetProperties(box, parent, manager);
box.SizeMode = ImageMode;
if (!string.IsNullOrEmpty(ImageAsset))
box.Image = manager.Content.Load<Texture2D>(ImageAsset);
else if (AtlasAsset != null)
{
if (AtlasAsset.Atlas == "IconProvider")
box.Image = IconProvider.GetByName(AtlasAsset.Name);
else
box.Image = Provider.GetAtlas(AtlasAsset.Atlas).GetTexture(AtlasAsset.Name);
}
if (!string.IsNullOrEmpty(Draw))
box.Draw += delegate(object sender, DrawEventArgs e)
{
if (EventFieldDraw == null)
{
Type classType = parent.GetType();
EventFieldDraw = classType.GetMethod(Draw);
}
if (EventFieldDraw == null)
throw new Exception("Could not find: " + Draw + " method");
EventFieldDraw.Invoke(parent, new object[] { sender, e });
};
break;
case "Label":
Label label = new Label(manager);
label.Init();
SetProperties(label, parent, manager);
label.Text = Text.StartsWith("TXT_KEY_") ? Provider.Instance.Translate(Text) : Text;
break;
case "GameMapBox":
GameMapBox mapBox = new GameMapBox(manager);
mapBox.Init();
SetProperties(mapBox, parent, manager);
break;
case "SideBar":
SideBar sideBar = new SideBar(manager);
sideBar.Init();
SetProperties(sideBar, parent, manager);
if (!string.IsNullOrEmpty(Draw))
sideBar.Draw += delegate(object sender, DrawEventArgs e)
{
if (EventFieldDraw == null)
{
Type classType = parent.GetType();
EventFieldDraw = classType.GetMethod(Draw);
}
if (EventFieldDraw == null)
throw new Exception("Could not find: " + Draw + " method");
EventFieldDraw.Invoke(parent, new object[] { sender, e });
};
break;
case "ContextMenu":
ContextMenu contextMenu = new ContextMenu(manager);
contextMenu.Init();
contextMenu.Name = Name;
contextMenu.Tag = this;
contextMenu.Passive = Passive;
contextMenu.Enabled = Enabled;
foreach (MenuItemEntry entry in Items)
{
MenuItem menuItem = new MenuItem(entry.Title);
menuItem.Enabled = entry.Enabled;
contextMenu.Items.Add(menuItem);
}
//.........这里部分代码省略.........
示例9: SetProperties
private void SetProperties(Control c, Control parent, Manager manager)
{
c.Name = Name;
//c.Top = Top < 0 ? manager.GraphicsDevice.Viewport.Height + Top : Top;
//c.Left = Left < 0 ? manager.GraphicsDevice.Viewport.Width + Left : Left;
if (!string.IsNullOrEmpty(Parent))
{
c.Top = Top < 0 ? parent.GetControl(Parent).Height + Top : Top;
c.Left = Left < 0 ? parent.GetControl(Parent).Width + Left : Left;
}
else
{
c.Top = Top < 0 ? parent.Height + Top : Top;
c.Left = Left < 0 ? parent.Width + Left : Left;
}
c.Width = Width;
c.Height = Height;
c.StayOnBack = StayOnBack;
c.StayOnTop = StayOnTop;
c.Passive = Passive;
c.Enabled = Enabled;
if (TextColor != Color.Transparent)
c.TextColor = TextColor;
else
c.TextColor = Color.White;
if (BackColor != Color.Transparent)
c.BackColor = BackColor;
if (Color != Color.Transparent)
c.Color = Color;
c.Tag = this;
c.Visible = Visible;
if (!string.IsNullOrEmpty(ToolTip))
{
ToolTip = ToolTip.Trim();
c.ToolTipType = typeof(EnhancedToolTip);
c.ToolTip.Text = ToolTip;
c.ToolTip.MaximumWidth = 240;
c.ToolTip.MinimumWidth = 240;
c.ToolTip.Height = ToolTip.Split(new char[] { '\n' }).Length * 20;
}
if (!string.IsNullOrEmpty(Parent))
c.Parent = parent.GetControl(Parent);
else
parent.Add(c);
}
示例10: Survey_AddTextBox
// This function adds a TextBox to the passed control collection, along
// with an associated Label control to display the survey question.
private Point Survey_AddTextBox(XmlNode inNode , Control.ControlCollection inControls,
Point location ,string tag)
{
// Create a new control.
TextBox myText = new TextBox();
// Fill in some of the appropriate properties
if (inNode.SelectSingleNode("defaultResponse") != null)
{
myText.Text = inNode.SelectSingleNode("defaultResponse").InnerText;
}
if (inNode.Attributes["name"] != null) {
myText.Name = inNode.Attributes["name"].Value;
}
myText.Tag = tag;
myText.Width = CONTROL_WIDTH;
// set {the MaxLength property based off of the XML node information.
if (inNode.SelectSingleNode("maxCharacters") != null) {
myText.MaxLength = int.Parse(inNode.SelectSingleNode("maxCharacters").InnerText);
}
// Calculate the number of lines that should be allowed for
if (myText.MaxLength > 0)
{
int numLines = (myText.MaxLength / CHARS_PER_LINE ) + 1;
// Calculate how large the textbox should be, and whether
// scrollbars are necessary.
if (numLines == 1)
{
myText.Multiline = false;
}
else
{
if (numLines >= 4)
{
myText.Multiline = true;
myText.Height = 4 * HEIGHT_PER_LINE;
myText.ScrollBars = ScrollBars.Vertical;
}
else
{
myText.Multiline = true;
myText.Height = numLines * HEIGHT_PER_LINE;
myText.ScrollBars = ScrollBars.None;
}
}
}
// Create a Label and add it to the collection
Label myLabel = new Label();
myLabel.Name = myText.Name + "Label";
if (inNode.SelectSingleNode("text") != null) {
myLabel.Text = inNode.SelectSingleNode("text").InnerText;
}
myLabel.Width = CONTROL_WIDTH;
// Add the control to the Controls collection, and reset
// the location to the location for the next control.
myLabel.Location = location;
inControls.Add(myLabel);
location.Y += myLabel.Height;
// Add the control to the Controls collection, and reset
// the location to the location for the next control.
myText.Location = location;
inControls.Add(myText);
location.Y += myText.Height + 10;
// Send back the location for the next control.
return location;
}
示例11: Survey_AddRadioButtons
// This function adds a GroupBox to the passed control collection, along
// with all the appropriate radio buttons, one for each available response.
// It also adds an associated Label control to display the survey question.
private Point Survey_AddRadioButtons(XmlNode inNode, Control.ControlCollection inControls ,
Point location ,string tag)
{
// Must create a GroupBox to contain the radio buttons
// otherwise they are not logically distinct from the other
// radio buttons on the form.
GroupBox myGroupBox = new GroupBox();
// set {up some properties for the control.
myGroupBox.Text = "";
myGroupBox.Name = inNode.Attributes["name"].Value;
myGroupBox.Tag = tag;
myGroupBox.Width = CONTROL_WIDTH + 20;
// Create some useful variables to use in the following block of code.
Point myRadioPoint = new Point(5, 10);
// Loop through each response, and add it as a new radio button.
foreach(XmlNode myNode in inNode.SelectNodes("responses/response"))
{
// Create the radio button.
RadioButton myRadio = new RadioButton();
// Add the appropriate properties.
myRadio.Text = myNode.InnerText;
myRadio.Location = myRadioPoint;
myRadioPoint.Y += myRadio.Height;
// set {the default value as the selected radio button, but
// only if the default attribute exists and is set to true.
if (myNode.Attributes["default"] != null)
{
if (myNode.Attributes["default"].Value == "true")
{
myRadio.Checked = true;
}
}
// Add the control to the group box.
myGroupBox.Controls.Add(myRadio);
}
// Reset the height for the textbox, based on the
// contained Radio Buttons.
myGroupBox.Height = myRadioPoint.Y + 5;
// Create a Label and add it to the collection.
Label myLabel = new Label();
// Fix the label properties.
myLabel.Name = myGroupBox.Name + "Label";
myLabel.Text = inNode.SelectSingleNode("text").InnerText;
myLabel.Width = CONTROL_WIDTH;
// Add the control to the Controls collection, and reset
// the location to the location for the next control.
myLabel.Location = location;
inControls.Add(myLabel);
location.Y += myLabel.Height - 5;
// Add the control to the Controls collection, and reset
// the location to the location for the next control.
myGroupBox.Location = location;
inControls.Add(myGroupBox);
location.Y += myGroupBox.Height + 10;
// Send back the location for the next control
return location;
}
示例12: Survey_AddListBox
// This function adds a ListBox to the passed control collection, along
// with an associated Label control to display the survey question.
private Point Survey_AddListBox(XmlNode inNode , Control.ControlCollection inControls ,
Point location ,string tag, bool isMultiSelect)
{
// Create a new control.
ListBox myList = new ListBox();
// set {up some properties for the control
myList.Text = "";
myList.Name = inNode.Attributes["name"].Value;
myList.Tag = tag;
myList.Width = CONTROL_WIDTH;
// Since this function can be used with either multi or single select
// list boxes, set the proper SelectionMode based on the passed
// isMultiSelect bool variable.
if (isMultiSelect)
{
myList.SelectionMode = SelectionMode.MultiSimple;
}
else
{
myList.SelectionMode = SelectionMode.One;
}
// Create a temporary XML Node to use when retrieving information
// about the response nodes in the passed node.
// Add the InnerText of the response nodes as the values for
// the list box options.
foreach(XmlNode myNode in inNode.SelectNodes("responses/response"))
{
myList.Items.Add(myNode.InnerText);
// if a default has been specified, use it as the current text.
if (myNode.Attributes["default"] != null)
{
if (myNode.Attributes["default"].Value == "true") {
myList.Text = myNode.InnerText;
}
}
}
// Create a Label and add it to the collection
Label myLabel = new Label();
// set {up some properties for the control
myLabel.Name = myList.Name + "Label";
myLabel.Text = inNode.SelectSingleNode("text").InnerText;
myLabel.Width = CONTROL_WIDTH;
// Add the control to the Controls collection, and reset
// the location to the location for the next control.
myLabel.Location = location;
inControls.Add(myLabel);
location.Y += myLabel.Height;
// Add the control to the Controls collection, and reset
// the location to the location for the next control.
myList.Location = location;
inControls.Add(myList);
location.Y += myList.Height + 10;
// Send back the location for the next control
return location;
}
示例13: Survey_AddComboBox
// This function adds a ComboBox to the passed control collection, along
// with an associated Label control to display the survey question.
private Point Survey_AddComboBox(XmlNode inNode ,Control.ControlCollection inControls,
Point location ,string tag)
{
// Create a new control.
ComboBox myCombo = new ComboBox();
// set {up some properties for the control
myCombo.Text = "";
myCombo.Name = inNode.Attributes["name"].Value;
myCombo.Tag = tag;
myCombo.Width = CONTROL_WIDTH;
// Create a temporary XML Node to use when retrieving information
// about the response nodes in the passed node.
// get {the response nodes.
foreach(XmlNode myNode in inNode.SelectNodes("responses/response"))
{
// Add the InnerText of the response nodes as the values for
// the drop down options.
myCombo.Items.Add(myNode.InnerText);
// if a default has been specified, use it as the current text.
if (myNode.Attributes["default"] != null) {
if (myNode.Attributes["default"].Value == "true")
{
myCombo.Text = myNode.InnerText;
}
}
}
// Create a Label and add it to the collection
Label myLabel = new Label();
// set {up some properties for the control
myLabel.Name = myCombo.Name + "Label";
myLabel.Text = inNode.SelectSingleNode("text").InnerText;
myLabel.Width = CONTROL_WIDTH;
// Add the control to the Controls collection, and reset
// the location to the location for the next control.
myLabel.Location = location;
inControls.Add(myLabel);
location.Y += myLabel.Height;
// Add the control to the Controls collection, and reset
// the location to the location for the next control.
myCombo.Location = location;
inControls.Add(myCombo);
location.Y += myCombo.Height + 10;
// Send back the location for the next control to be added.
return location;
}