Visual studio - toggle switch hiding text blocks? [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am doing a school project and i can´t figure out how to "hide" some text blocks when the toggle switch is on and the opposite? Developing a windows 8 app. Thanks and btw. How do you make a collection from multiple text blocks(XAML)?
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
}

Assuming your control structure is fairly flat, you can get by using the Tag property on the TextBox. In your XAML, put some distinct value in the Tag field for each TextBox you want to make toggle-able, like the word 'CanToggle'. Then you can do something like
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
foreach (Control currentControl in this.Children)
{
if (currentControl.Tag == "CanToggle")
currentControl.Visible = !currentControl.Visible;
}
}
If your control collection is not flat, then you'll have to figure out how to dig recursively through the collection of controls to locate all the TextBox that you want to toggle. This answer may help.

Visual Studio Main Menu - Edit - Outlining - Toggle All Outlining: Ctrl+M, Ctrl+L
Personally, I use Ctrl+M to "collapse to defininitions" more than anything else though.

Related

How to swap two images in Xamarin Forms [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I have created a currency converter app in Xamarin forms in which we have two Image controls that contain the country flags. Now, if the user clicks the swap button, the flags swap each other.
For example, the source of the first image will go to the second image, and vice versa.
<Image Source="usaflag.png" x:Name="Img1"/>
<Image Source="australiaflag.png" x:Name="Img2"/>
<Button Text="SWAP" x:Name="BtnSwap" Clicked="BtnSwap_OnClicked"/>
Here's my XAML Code. I know the we will write the swapping code in the code behind file. I am not using the MVVM style pattern so if you've any code regarding swapping then kindly share it with me.
Okay, so you want to swap two images in xamarin forms. Well, that's pretty simple!
You just need to add this code inside the OnClick() event of a button.
private void BtnSwap_OnClicked(object sender, EventArgs e)
{
var firstImage = Img1.Source;
var secondImage = Img2.Source;
Img2.Source = firstImage;
Img1.Source = secondImage;
}
In this case, you can Bind the sources and change those values on BtnSwap_OnClicked.

Using a Label vs using a Textbox [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I have a C# Application where I am using Serial communication with a Microcontroller to Display data on the application. I have used a text box to display the data :
public void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
try
{
DataRec = serialPort1.ReadExisting();
int.TryParse(DataRec, out myTotal);
this.BeginInvoke(new EventHandler(DisplayText));
}
catch(NullReferenceException)
{
//catching the exception
}
}
public void DisplayText(object sender, EventArgs e)
{
textBox2.Text = myTotal.ToString();
}
Instead of TextBoxes I have also tried using labels. I get the same result and I didnt see any change in performance. I am using labels because I didnt want the user to think they can edit the values in the textboxes.
I have tried searching for the advantages of one over the other. So far the ones I have seen is :
Textboxes need to be set as readonly whereas in labels you dont need to do that.
Even when I set the textboxes as read only the Cursor is still visible whereas in Label it isn't.
What are some of the pros and cons in terms of performance, while using either a Label or Textbox?
Is it ok if I use labels ?
There are a few pro's and con's to both.
Label
Pro's:
Text is not copy able
Cursor does not change
Sets size based on text (if autosize is on, I think its on by default)
Option to align text to the right (autosize off)
Con's:
Text is not selectable/copy able
Text might outgrow form/parent with autosize
TextBox
Pro's:
Text is copy able
Fixed size (also a con)
Con's:
Does not autosize
Height not adjustable (does not apply to rich textbox/multiline = true)
My opinion:
In my opinion you should use a label if the user shouldn't be able to copy the data. The exception to this is if you have just 1 un-editable value and all others are textbox's, then you should just make a readonly textbox.
You have already answered your own question. It seems clear to me that a label is more appropriate in this case. You could argue that later that you may need the extra functionality that the text box provides but you should consider the YAGNI principle.
As to pros and cons, the user will probably believe they are able to edit the value in the text box, they wont make that mistake using a label.

DataGridView need guidance with that [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Thank you for your time in advance, I need some help, I want to create a DataGridView in Windows form, and in this grid I want to enter data and when I hit enter it should save that data to database and create another line, I tried to find a good tutorial on it but didn’t succeeded. if there is any good example please let me know
And please I do NOT need the grid with save update etc buttons, It should save data upon hit enter and cursor moves to the next line of the grid
If there is any tutorial or example please let me know
You simply catch the Enter-key in the DataGridView.KeyDown event:
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
yourSaveRoutine();
dataGridView1.Rows.Add();
}
}

Call a class in Visual studio through a button [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i have this project in my visual studio and i have a form which is linked to a solution in a project.
So, i need to call it on a button click.
It's like:
private void button1_Click(object sender, EventArgs e)
{
poComp.Client.StartpoComp
}
The thing is i have not copied the code the right way, houw should it proceed?
What is the file's structure?
Sorry, i know this might sound dumb and it probably is but i'm right in the beginning.
Below will do what (I think) you want to do but I strongly advise that you google "using classes c#" to try and find some tutorials
Here is just one
private void button1_Click(object sender, EventArgs e)
{
StartpoComp spc = new poComp.Client.StartpoComp();
//myFormsLabel.Text = spc.SomePublicVariable;
//spc.SomePublicMethod(param1);
}

How to allow only valid values in a combobox? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
in C# with DotNet 4 i have a form with a combobox which is filled with values when starting the program.
Now user can dropdown and select one of the values.
But: It is also possible to write something new into the combobox-field.
Question: What can i do that it is NOT possible to write something which is not part of the list?
Thanks
To make the text portion of a ComboBox non-editable, set the DropDownStyle property to "DropDownList".
It can be done by simply assigning a property to combobox .DropDownStyle = ComboBoxStyle.DropDownList. but, this property do not allow to edit text. means you have to select item either by mouse or by up/down arrow key. You cannot filter result by selecting this property. if you wish to filter result but don't allow to accept invalid value then you can do this by writing some code in cmb_Validating event
private void cmb_Validating(object sender, CancelEventArgs e)
{
if (cmb.SelectedValue == null && cmb.Text != string.Empty)
e.Cancel=true;
}

Categories