i have the following FlowDirectionPanel http://prntscr.com/aao6lt as you can see those are achievements for a poker game.When you get a new achievement a yes/no messageBox pops up and it ask's you if you want to go and check out your new acquirement if you press yes I want to be able to automatically navigate to the newly unlocked achievement which are contained in the FlowDirectionPanel which looks like in the image above. Also each achievement is contained in another panel which is children of the flowPanel if you look closer you can see that they have some outline border. I create and add the panels dynamically but they do have names which can help me to navigate to the desired panel. This is how i create them:
public void PanelForAchievements(Form currentForm, FlowLayoutPanel flp, AchivementRequirements achivement)
{
FlowLayoutPanel retFlp = flp;
string pGetAchivementName = #"pGet" + achivement.Name;
string lbAchivementName = #"lb" + achivement.Name;
string lbAchivementRewardName = #"lb" + achivement.Name + #"Reward";
string cbGetAchivementName = #"cbGet" + achivement.Name;
string pbAchivementName = #"pb" + achivement.Name;
var pGetAchivement = new Panel
{
Name = pGetAchivementName,
Size = new Size(retFlp.Width, 100),
BorderStyle = BorderStyle.FixedSingle,
};
currentForm.Controls.Add(pGetAchivement);
var lbAchivement = new Label
{
Name = lbAchivementName,
Location = new Point(pGetAchivement.Location.X, pGetAchivement.Location.Y),
Size = new Size(135, 30),
AutoSize = false,
BorderStyle = BorderStyle.FixedSingle,
Font = new Font("Microsoft Sans Serif", 10F, FontStyle.Regular, GraphicsUnit.Point, (byte)0),
Text = achivement.TitleText,
};
var lbAchivementReward = new Label
{
Name = lbAchivementRewardName,
AutoSize = true,
Top = (pGetAchivement.Height - pGetAchivement.Height) / 2,
Text = achivement.RewardLabelText,
TabIndex = 2,
BorderStyle = BorderStyle.FixedSingle,
Location = new Point(lbAchivement.Location.X, lbAchivement.Location.Y + lbAchivement.Height + 5)
};
var cbGetAchivement = new CheckBox
{
Name = cbGetAchivementName,
AutoCheck = false,
AutoSize = true,
Location = new Point(lbAchivement.Location.X + lbAchivement.Width + 10, lbAchivement.Location.Y),
TabIndex = 1,
UseVisualStyleBackColor = true
};
achivement.IsUnlocked(MainPoker.AllAchievements[achivement.EnumCasted], achivement.Requirement,cbGetAchivement);
var pbAchivement = new PictureBox
{
BorderStyle = BorderStyle.Fixed3D,
Name = pbAchivementName,
Dock = DockStyle.Right,
BackgroundImageLayout = achivement.PictureBoxImageLayout,
//Location = new Point(pGetAchivement.Right, pGetAchivement.Location.Y),
Size = new Size(145, 90),
SizeMode = PictureBoxSizeMode.Zoom,
TabIndex = 9,
TabStop = false,
Image = achivement.PackPreview,
};
pGetAchivement.Controls.Add(lbAchivement);
pGetAchivement.Controls.Add(lbAchivementReward);
pGetAchivement.Controls.Add(cbGetAchivement);
pGetAchivement.Controls.Add(pbAchivement);
retFlp.Controls.Add(pGetAchivement);
achivement.Title = lbAchivement;
achivement.RewardLabel = lbAchivementReward;
achivement.Unlocked = cbGetAchivement;
achivement.Preview = pbAchivement;
}
It's just simple code and this is how i initialize them :
public static RoyalFlush RoyalFlush = new RoyalFlush(1, new Tuple<string, int?>("Royal Card Pack", 100000));
private readonly CreatePanels _createAchivementPanels = new CreatePanels();
foreach (var achi in AchivementRequirements.AchivementList)
{
_createAchivementPanels.PanelForAchievements(this, pAchievementsCards, achi);
//im also doing other stuff here..
//pAchivementsCards is the name of the FlowDirectionPanel
}
Now by the time the yes/no messageBox is shown i already know which achievement is unlocked and also my achievements have classes as seen above public static RoyalFlush RoyalFlush and those classes have property - Name which obviously contains the name of the achievement im using this name to create respective names for each control i create from public static RoyalFlush RoyalFlushfor example :
string pGetAchivementName = #"pGet" + achivement.Name;
p stands for panel and i simply just get the current achievement name using the property achivement.Name and we end up with something like this : pRoyalFlush as a name for our panel. Now that i know the name of the panel and which achievement is being unlocked i need to navigate through my FlowDirectionPanel and find the specific panel and leave the focus there. I have no idea how to do that i will show an example with pictures of what i want if it's not clear by now :
First we unlock new achievement and we get the yes/no mbox : http://prnt.sc/aaodyr
Now we press the Yes button which will redirect us to my new form and show us the achievement FlowDirectionPanel : h.t.t.p.:/./.prntscr.com/aaofft here the program see's that the achievement for Full House is completed and it should show it in the middle of the screen with a nice border just like so : h.t.t.p.:././.prntscr.com/aaoh40
I dont have reputation to post more than 2 links so i had to put some dots in them ..
It's my first question and my native language is not English so excuse me for any mistakes I made.
you may make some foreahc loop, where you compare names, and then, when you find the control you need, scroll your flowlayoutpanel to it. For example, my flowlayoutpanel has 4 buttons, and only 2 of them are visible, and I want to scroll to button4:
foreach (Control c in flowLayoutPanel1.Controls)
{
if ((c as Button).Name == "button4")
{
(c as Button).Focus();
flowLayoutPanel1.ScrollControlIntoView(c);
break;
}
}
Hope I andrestand your question correctly.
Related
I have a canvas which contains a panel housing a scroll view. (The scroll view contains the default Viewport -> Content setup). I don't think it's relavent but I removed the scroll bars.
I want to display a dynamic list of prefabs (buttons) in the scroll view. When debugging, I can see that the prefabs are being created correctly with the Content as the parent, but nothing shows up in the scrollview.
I followed a tutorial that had me add Vertical Layout Group and Content Size Fitter components to the Content GameObject. I tried to play around with the options in those components while running to see if I had them misconfigured, but the prefabs were never displayed.
Before running:
After running:
Shouldn't really matter much but here's the code I am using for testing. (In Start() - and I know this isn't the most efficient.)
for (int i = 0; i < 5; i++)
{
Game game = new Game
{
ID = i.ToString(),
OpponentID = i.ToString(),
OpponentImage = "pig",
OpponentName = "Test " + i,
OpponentScore = new Score { Pigs = 2, Bulls = 1 },
Points = 350,
Score = new Score { Pigs = 1, Bulls = 1 },
Status = "active",
Turn = "6XMvi7Xv2maXDdFN7dwrhLaMrkE3"
};
var gameObj = Instantiate(gamePrefab, scrollViewContent.transform, false);
var canvas = gameObj.transform.Find("Canvas").GetComponent<Canvas>();
canvas.enabled = false;
var gameObjButton = canvas.transform.GetChild(0);
gameObjButton.Find("OpponentInfo").Find("OpponentName").GetComponent<Text>().text = game.OpponentName;
gameObjButton.Find("OpponentInfo").Find("OpponentScore").GetComponent<Text>().text = game.OpponentScore.ToString();
// // gameObj.transform.Find("OpponentProfilePicture").GetComponent<Image>()
gameObjButton.Find("OpponentInfo").Find("Status").GetComponent<Text>().text = GameObject.Find("FirebaseRef")?.GetComponent<FirebaseRef>()?.user?.UserId;
gameObjButton.Find("PlayerInfo").Find("PlayerScore").GetComponent<Text>().text = game.Score.ToString();
gameObjButton.Find("PlayerInfo").Find("PlayerPoints").GetComponent<Text>().text = game.Points.ToString();
canvas.enabled = true;
}
Hi I'm working on Windows application and I'm adding data inside the panel dynamically however data is not showing it completely inside the panel because of font size but I don't want to resize font.
tblLayoutModule.Controls.Add(new Label() {
Text = string.Concat(pModuleName, " ", pVersion),
Padding = new Padding() { Top = 2 },
UseMnemonic = false }
);
Try to add autosize = true could work for you
tblLayoutModule.Controls.Add(
new Label() {
Autosize = true,
Text = string.Concat(pModuleName,"",pVersion),
Padding = new Padding() { Top = 2 },
UseMnemonic = false }
);
I trying to build a method to draw my form dynamically, this method receives a list of questions, from this we draw a form and show each question (label) and an option (yes/no - radio buttons).
I can add each control created before in my Forms.Controls, but when the form opens, just one question is rendered passing a list with more than 20 questions. Why? Did I forget to do something?
This method builds all my components to the form based on my list of questions.
private void BuildComponents(List<Question> properties)
{
this.propertyList = new List<System.Windows.Forms.Control>();
for (int i = 0; i < properties.Count; i++)
{
var newLabel = new System.Windows.Forms.Label
{
AutoSize = true,
Location = new System.Drawing.Point(13 + i + 5, 13),
Name = properties[i].Label,
Size = new System.Drawing.Size(699, properties[i].Description.Length),
TabIndex = i,
Text = properties[i].Description,
};
var newYesRadioButton = new System.Windows.Forms.RadioButton
{
AutoSize = true,
Location = new System.Drawing.Point(13 + i + 5, 34),
Name = "radioButton" + i + 1,
Size = new System.Drawing.Size(52, 21),
TabIndex = i + 1,
TabStop = true,
Text = "Sim",
UseVisualStyleBackColor = true
};
var newNoRadioButton = new System.Windows.Forms.RadioButton
{
AutoSize = true,
Location = new System.Drawing.Point(71 + i + 5, 34),
Name = "radioButton" + i + 2,
Size = new System.Drawing.Size(55, 21),
TabIndex = i + 1,
TabStop = true,
Text = "Não",
UseVisualStyleBackColor = true
};
propertyList.Add(newLabel);
propertyList.Add(newYesRadioButton);
propertyList.Add(newNoRadioButton);
};
}
This method initializes my form and add all properties built in this.Controls
private void InitializeComponent()
{
this.BuildComponents(questions);
foreach (var property in propertyList)
{
this.Controls.Add(property);
}
}
I would recommend you to use FlowLayoutPanel and UserControls. With FlowLayoutPanel you can put usercontrols one after another and you dont need to deal with the location property.
In addition, you should not change InitializeComponent..
Actually, you dont need to touch the code in the designer file!
I'm currently trying to change FlatAppearance.BorderSize, when creating a button via Control.Add(new Button()) method but when using:
Controls.Add (new Button(FlatAppearance.BorderSize = 0,))
it just returns an error saying that FlatAppearance does not exist. The buttons are created one after another listing information about songs. Each Section is created button by button in a FlowLayoutPanel. Is there any work around for removing the border on the button?
selectTrackNo.Connection = DB.connect;
MySqlDataReader trackNoReader = selectTrackNo.ExecuteReader();
while (trackNoReader.Read())
{
flpTrackNo.Controls.Add(new Button
{
Name = "lblTrackNo" + x,
Text = trackNoReader[0] as string,
BackColor = Color.Transparent,
FlatStyle = FlatStyle.Flat,
AutoSize = false,
Dock = DockStyle.Top,
Width = flpArtist.Width,
ForeColor = ColorTranslator.FromHtml("#3c3c3c"),
Font = new Font("Trebuchet MS", 9),
Enabled = true,
TextAlign = ContentAlignment.MiddleLeft,
});
x++;
}
this then repeats for every column in the Form.
Many thanks
- Ross
You will need a couple more squiggly brackets:
this.Controls.Add(new Button() { FlatAppearance = { BorderSize = 0 }});
i'm making a simple login-register program, i save usernames and passwords in lists.
i'm trying to show all the usernames under each other and that it wil repeat everytime a new user will be registered.
for some reason it only shows the last user, and that's it.
for (Int32 i = 0; i < frmLogin.reg_usernames.Count; i++ )
{
TextBox lbl = new TextBox { Location = new Point(15, 30), BorderStyle = BorderStyle.Fixed3D, BackColor = Color.AliceBlue, Font = new Font(Font.FontFamily.Name, 9), ScrollBars = ScrollBars.Vertical };
this.Controls.Add(lbl);
lbl.Text = frmLogin.reg_usernames[i];
}
You need to move the boxes down as you go:
TextBox lbl = new TextBox { Location = new Point(15, 30 * i), BorderStyle ....
Note that your form would need to be large enough to see them all, as well. You may need to set your height appropriately, or place the text boxes inside of a container which could scroll, instead of directly on the form itself.