WP7 Textbox with title inside of textbox - windows-phone-7

I would like to have a textbox that lets a user enter some text (obviously). Let's say it's 'Title'. Is there a pre-built control that shows the name of the field (Title in this case) inside of the text box and then have it clear out when the user enter the field. Example: The search box at the top of this page has 'Search' but when you enter the box it goes away.

Watermarked TextBox
I think I remember it also being in the Mango Silverlight Toolkit too, correct me if I'm wrong:
Mango Silverlight Toolkit

This is an example. Put the GotFocus and LostFocus event in your textbox(in .xaml page).
<TextBox x:Name="UrlTextBox" Text="Search" Margin="0,0,98,0" GotFocus="UrlTextBox_GotFocus" LostFocus="UrlTextBox_LostFocus"/>
In xaml.cs page, add the following codes-
private void UrlTextBox_GotFocus(object sender, RoutedEventArgs e)
{
if (UrlTextBox.Text == "Search")
{
UrlTextBox.Text = "";
SolidColorBrush Brush1 = new SolidColorBrush();
Brush1.Color = Colors.Gray;
UrlTextBox.Foreground = Brush1;
}
else
{
char[] strDataAsChars = UrlTextBox.Text.ToCharArray();
int i = 0;
for (i = UrlTextBox.SelectionStart - 1; ((i >= 0) &&
(strDataAsChars[i] != ' ')); --i) ;
int selBegin = i + 1;
for (i = UrlTextBox.SelectionStart; ((i < strDataAsChars.Length) &&
(strDataAsChars[i] != ' ')); ++i) ;
int selEnd = i;
UrlTextBox.Select(selBegin, selEnd - selBegin);
}
}
private void UrlTextBox_LostFocus(object sender, RoutedEventArgs e)
{
if (UrlTextBox.Text == String.Empty)
{
UrlTextBox.Text = "Search";
SolidColorBrush Brush2 = new SolidColorBrush();
Brush2.Color = Colors.Gray;
UrlTextBox.Foreground = Brush2;
}
}

Related

I'm trying to make upgrade system I cannot find way to save this data after when I Start game

private void Update()
{
Score.text = puanlama.ToString();
if (puanlama < firstbarvalue)//used for first bar value to open button activeness
{
activeness.interactable = false;
}
if (puanlama >= firstbarvalue && counterbars == 1)//counterbar for button activeness
{
textforvalues.text = firstbarvalue.ToString();// button value on it
activeness.interactable = true;
}
if (counterbars == 2)
{
activeness.interactable = false;
}
if (puanlama >= secondbarvalue && counterbars == 2)
{
textforvalues.text = secondbarvalue.ToString();
activeness.interactable = true;
}
if (counterbars == 3)
{
activeness.interactable = false;
}
}
public void Buttonactiveness()// Button activeness that I assign to my button[Here button and bars that I used][1]
{
if (puanlama >= firstbarvalue && counterbars == 1)
{
Fuelbars[0].SetActive(true);
for (int i = 1; i < Fuelbars.Length; i++)
{
Fuelbars[i].SetActive(false);
}
puanlama = puanlama - firstbarvalue;
counterbars++;
}
else if (puanlama >= secondbarvalue && counterbars == 2)//Bars which is second one
{
Fuelbars[0].SetActive(true);
Fuelbars[1].SetActive(true);
for (int i = 2; i < Fuelbars.Length; i++)
{
Fuelbars[i].SetActive(false);
}
puanlama = puanlama - secondbarvalue;
counterbars++;
}
I'm trying to put some code to turn this code to player pref and save this data.
playerpref counter bar is not working any suggest
Button activeness that I assign to my buttonHere button and bars that I used
Fuelbars which I'm trying to add is important part of work
counterbar for button activeness
In update section I tried to control button activeness and I changed button text

How to make entry like editor in Xamarin.Forms?

I am creating a mobile application in that I need to send a message for query or support when the user creates that type of message and then click on return or done from keyboard entry height should be adjusted and if the user clicks on the back than it should also be managed. In that, I am not able to use Editor control.
I am using a shared project to develop the application.
I try with the following code:
Sample.xaml
<StackLayout Padding="50" HeightRequest="150">
<Entry TextChanged="Entry_TextChanged" x:Name="EntryCustom"/>
</StackLayout>
Sample.xaml.cs
private void Entry_TextChanged(object sender, TextChangedEventArgs args)
{
int isElse = 0;
if (args != null && args.OldTextValue != null && args.NewTextValue != null)
{
string[] oldval = args.OldTextValue.Split('\r');
string[] Newval = args.NewTextValue.Split('\r');
if (oldval.Count() > Newval.Count())
{
EntryCustom.HeightRequest = EntryCustom.HeightRequest - 33;
isElse = 2;
}
else
isElse = 1;
}
if (args.OldTextValue != null && (args.NewTextValue == "\n" || args.NewTextValue.EndsWith("\r")) && EntryCustom.HeightRequest < 100 && (isElse == 1 || args != null || args.OldTextValue.Count() > args.NewTextValue.Count()))
EntryCustom.HeightRequest = EntryCustom.HeightRequest + 33;
}
Can anyone look into this and suggest me what should I have to change in the code?
You should use an Editor. Use <Editor AutoSize="TextChanges"/> and the editor will adjust it's size based on the entered text.

winforms, help needed to create a dynamic tablelayoutpanel with buttons

I am trying to create a dynamic tablelayout which creates adds a skill and gives that skill 1 level and a increase decrease button. I am struggling with having the buttons access the level label. I thought about finding the location of the button that was clicked, but could figure out how to do that.
In advance, Thank you.
example:
1
this is what i have so far:
private void skilladded(object sender, EventArgs e)
{
int i = 1;
int[] position= { 0,0};
bool test = false;
//string select;
int k=0;
for (i=1;i<=skillstableLayoutPanel.RowCount;i++)
{
Control c= skillstableLayoutPanel.GetControlFromPosition(0,i);
if (c!=null&&addskillswin.selected==c.Text)
{
test = true;
k = i;
break;
}
else if(c==null)
{
k = i;
break;
}
}
if (test==false)
{
Label newskill = new Label();
Label newskilllvl = new Label();
TableLayoutPanel buttontable = new TableLayoutPanel();
Button up = new Button();
Button down = new Button();
buttontable.ColumnCount = 2;
buttontable.RowCount = 1;
buttontable.RowStyles.Add(new RowStyle(SizeType.Percent,100f));
buttontable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent,50f));
buttontable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50f));
buttontable.Margin = new Padding(0,0,0,0);
buttontable.Dock = DockStyle.Fill;
buttontable.Controls.Add(up, 0, 0);
buttontable.Controls.Add(down, 1, 0);
up.BackgroundImage = Properties.Resources.up;[enter image description here][2]
down.BackgroundImage = Properties.Resources.down;
up.BackgroundImageLayout=ImageLayout.Stretch;
down.BackgroundImageLayout = ImageLayout.Stretch;
newskill.Text = addskillswin.selected;
newskilllvl.Text = "1";
up.Margin = new Padding(0, 0, 0, 0);
down.Margin = new Padding(0, 0, 0, 0);
skillstableLayoutPanel.Controls.Add(newskill,0,k);
skillstableLayoutPanel.Controls.Add(newskilllvl, 1, k);
skillstableLayoutPanel.Controls.Add(buttontable, 2, k);
skillavaillabel.Text = (Convert.ToInt32(skillavaillabel.Text) - 1).ToString();
skillpointlvl = Convert.ToInt32(newskilllvl.Text);
up.MouseClick += new MouseEventHandler(skillup);
down.MouseClick += new MouseEventHandler(skilldown);
}
if (test==true)
{
skillstableLayoutPanel.GetControlFromPosition(1, k).Text = (Convert.ToInt32(skillstableLayoutPanel.GetControlFromPosition(1, k).Text) + 1).ToString();
skillavaillabel.Text = (Convert.ToInt32(skillavaillabel.Text) -1).ToString();
}
}
private void skillup(object sender, EventArgs e)
{
skillpointlvl++;
}
private void skilldown(object sender, EventArgs e)
{
skillpointlvl--;
}
Instead of this:
up.MouseClick += new MouseEventHandler(skillup);
down.MouseClick += new MouseEventHandler(skilldown);
Try something like this:
up.MouseClick += ((o, me) =>
{
int currentLevel = Int32.Parse(newskilllvl.Text);
currentLevel++;
newskilllvl.Text = currentLevel.ToString();
});
down.MouseClick += ((o, me) =>
{
int currentLevel = Int32.Parse(newskilllvl.Text);
currentLevel--;
newskilllvl.Text = currentLevel.ToString();
});
Your skillup or skilldown event handler could potentially process each sender and see from which button the click originated, but you'd have to uniquely name each button and do a lot of string comparisons to see which button corresponds to which skill level label. The code above adds an anonymous handler to each button, which allows us to essentially tie the button being clicked to its corresponding skill label.
Personally though, I would not store all these values in labels like you have done. I would either store them in properties on the form, or better yet in a class of their own. I would also put all this logic somewhere else beside the form, like in a Presenter or Controller (or class library), and follow a design pattern such as MVC or MVP. This will make maintaining and changing the application easier in the long run.
Also, consider using camel case and Pascal case for your variable names. All lowercase variables are harder for experienced programmers to read.

replacing a submitlink with indicatingAjaxButton

I have a form with a submitbutton which will get results from a database and updates a listview based on these results. If there is no result, a feedback message is shown. This all works fine.
Now I want to replace the submitlink with an IndicatingAjaxButton, so the user can see something happening when getting the result takes a long time.
The basic idea is this:
IndicatingAjaxButton submitLink = new IndicatingAjaxButton("submit", form) {
private static final long serialVersionUID = -4306011625084297054L;
#Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
Integer hourFrom = 0;
Integer hourTo = 0;
Integer minuteFrom = 0;
Integer minuteTo = 0;
hourFrom = Integer.parseInt(hour_from.getModelObject());
hourTo = Integer.parseInt(hour_to.getModelObject());
minuteFrom = Integer.parseInt(minute_from.getModelObject());
minuteTo = Integer.parseInt(minute_to.getModelObject());
Calendar from = Calendar.getInstance();
Calendar to = Calendar.getInstance();
Date dateFrom = date_from.getModelObject();
Date dateTo = date_to.getModelObject();
from.setTime(dateFrom);
to.setTime(dateTo);
from.set(Calendar.HOUR, hourFrom);
from.set(Calendar.MINUTE, minuteFrom);
to.set(Calendar.HOUR, hourTo);
to.set(Calendar.MINUTE, minuteTo);
if (topicQueueSelect.getModelObject() == null) {
error("Please select a message name.");
getSession().setAttribute("error", "");
}
if (to.before(from)) {
error("Date to must be after date from.");
getSession().setAttribute("error", "");
}
cal.setTimeInMillis(System.currentTimeMillis());
if (from.after(cal)) {
error("Date from must be in the past.");
getSession().setAttribute("error", "");
}
if (getSession().getAttribute("error") != null) {
getSession().removeAttribute("error");
return;
}
page.setModelObject(1);
List<Search> searchFields = (List<Search>) searchFieldsField
.getModelObject();
messageKeyDataList = messageController.search(
topicQueueSelect.getModelObject(), searchFields,
from.getTime(), to.getTime(),
maxResults.getModelObject(), page.getModelObject(),
sortorder);
if (messageKeyDataList.size() == 0) {
info("Search criteria didn't produce any results.");
result.setList(messageKeyDataList);
resultContainer.setVisible(false);
return;
}
resultContainer.setVisible(true);
resultSize = messageController.getResultSize();
int pages = (int) Math.ceil((float) resultSize
/ maxResults.getModelObject());
ArrayList<Integer> pageNumbers = new ArrayList<Integer>();
for (int n = 1; n <= pages; n++) {
pageNumbers.add(n);
}
page.setChoices(pageNumbers);
pageunder.setChoices(pageNumbers);
showing.setDefaultModelObject("Showing 1 to "
+ messageKeyDataList.size() + " out of " + resultSize
+ " messages");
lastSearch.put("topicQueue", topicQueueSelect.getModelObject());
lastSearch.put("searchFields", searchFields);
lastSearch.put("from", from.getTime());
lastSearch.put("to", to.getTime());
lastSearch.put("maxResults", maxResults.getModelObject());
result.setList(messageKeyDataList);
target.add(feedback);
}
};
The SubmitLink does show me either the ResultView with the new list, or the info message, the IndicatingAjaxButton doesn't. I know the form submit is called, because the system.out is being printed.
Any suggestions on this?
SubmitLink is non-Ajax component. Using it will repaint the whole page!
IndicatingAjaxButton is an Ajax component. You need to use the passed AjaxRequestTarget to add components which should be repainted with the Ajax response. For example the FeedbackPanel should be added to the AjaxRequestTarget.
I found that I had to do setOutputMarkupPlaceholderTag(true) on both the resultContainer and the feedback. After that adding them to the requesttarget works as expected.

C# Windows form. How to use the button_click method?

I am using a for loop to keep adding items to an array by keep pressing the button, i call it btnEnter, after input some data.
something like
double[] inputarr = new double[10];
for (int i = 0; i < inputarr.Length; i++)
{
inputarr[i] = Double.Parse(txtAmount.Text);
}
I want to jump out from the loop and perform something by clicking another button. Can button_click() do the job for me?
like
for (int i = 0; i < inputarr.Length; i++)
{
inputarr[i] = Double.Parse(txtAmount.Text);
if (btnStop_Click() == true)
{
break;
}
}
how to make this work? can anyone help me with this?
If I understand you correctly, you want to prompt for input 10 times in a row. You're thought process is a bit inverted. I think all you need is a prompt dialog. See Prompt Dialog in Windows Forms for an example.
You can call another button like this
for (int i = 0; i < inputarr.Length; i++)
{
inputarr[i] = Double.Parse(txtAmount.Text);
btnStop_Click(null,null);
break;
}
}
or u can use timer
int i = 0;Timer t = new Timer();
button_click(object sender,event e)
{
t.Interval = 4000;
t.Tick += t_Tick;
t.Start();
}
void t_Tick(object sender, EventArgs e)
{
if (i <= 9) { inputarr[i] = Double.Parse(txtAmount.Text); }
else { t.Stop(); Do other staff }
i++;
}

Resources