Percentage using label - visual-c#-express-2010

With button + and - percentage varies from 0% to 100%.
Is there any way to show percentage with label like on this links (images) below.
image1
image2
PS I don't wont to use progress bar but if there is another better way please suggest

make + and - buttons and a label with that green background.
On click of plus or minus adjust height of label and text on label
private void plusButton_Click(object sender, RoutedEventArgs e)
{
if(percentLength.Height < 100)
percentLength.Height = percentLength.Height + 10;
}
private void minusButton_Click(object sender, RoutedEventArgs e)
{
if (percentLength.Height > 0)
percentLength.Height = percentLength.Height - 10;
}
protected void percentLength_HeightChanged(object sender, EventArgs e)
{
percentLength.Content = percentLength.Height + "%";
}

Related

Adding Duration in dateTimePicker

I have two DateTimePickers one as Start Time and other one as end time.
I also have a text box that has duration.
I would like to know how can I add the duration to start time datetimePicker to automatically get the end time in the endTime dateTimePicker?
Though I believe your Service Duration is a combobox, I've still used textbox as per your question.
Call textchanged. When text in textbox changes, the time is added to dateTimePicker2
private void textBox1_TextChanged(object sender, EventArgs e)
{
int mins = Convert.ToInt32(textBox1.Text);
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(mins);
}
For combobox, call textchanged as well.
private void comboBox1_TextChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == -1 || comboBox1.Text == null)
{
dateTimePicker2.Value = dateTimePicker1.Value;
}
else if (comboBox1.Text == "15")
{
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(15);
}
else if (comboBox1.Text == "30")
{
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(30);
}
else if (comboBox1.Text == "60")
{
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(60);
}
}

How to change text of a cell at runtime in XtraReport?

How to change text of a cell at runtime in XtraReport?
I am using "DevExpress v2011 vol 1".
I have a few cells and I can change their text one by one using PreviewClick event as below.
private void _cell_PreviewClick(object sender, PreviewMouseEventArgs e)
{
e.Brick.Text = "aaabbbccc"; e.PreviewControl.Refresh();
}
But, in that event I need to change text of other cells simultaneously. I tried below and got no luck
private void _cell_PreviewClick(object sender, PreviewMouseEventArgs e)
{
e.Brick.Text = "aaabbbcc";
otherCell1.Text = "rrrttcwwww"
e.PreviewControl.Refresh();
}
Best Regards,
Orgil.D
You can handle the DataSourceRowChanged event of the XtraReport Class
private void rpt_DataSourceRowChanged(object sender, DataSourceRowEventArgs e)
{
MyClass xx = bidingSource[e.CurrentRow] as MyClass ;
if (string.IsNullOrWhiteSpace(xx.WorkDescription))
{
xrTableCell25.Visible = false;
xrTableRow3.Visible = false;
xrTableCell25.Text = "456";
}
else
{
xrTableCell25.Visible = true;
xrTableRow3.Visible = true;
xrTableCell25.Text = "123";
}
}

Binding TextArea height to its content

JavaFX: Is it possible to bind TextArea height (row count) to the height of its content?
I would like to dynamically change height of TextArea while writing the text.
Have a look at JavaFX utility class. Although this is not a solution using binding, computeTextHeight(Font font, String text, double wrappingWidth) method can help you.
This is an exact, simple & working solution:
SimpleIntegerProperty count = new SimpleIntegerProperty(20);
int rowHeight = 10;
txtArea.prefHeightProperty().bindBidirectional(count);
txtArea.minHeightProperty().bindBidirectional(count);
txtArea.scrollTopProperty().addListener(new ChangeListener<Number>(){
#Override
public void changed(ObservableValue<? extends Number> ov, Number oldVal, Number newVal) {
if(newVal.intValue() > rowHeight){
count.setValue(count.get() + newVal.intValue());
}
}
});
Alternatively you can use lambdas to simply the syntax even further:
SimpleIntegerProperty count=new SimpleIntegerProperty(20);
int rowHeight = 10;
textArea.prefHeightProperty().bindBidirectional(count);
textArea.minHeightProperty().bindBidirectional(count);
textArea.scrollTopProperty().addListener((ov, oldVal, newVal) -> {
if(newVal.intValue() > rowHeight){
count.setValue(count.get() + newVal.intValue());
}
});
A solution that workq fine in javafx8 (hiding toolbar is inspired from JavaFX TextArea Hiding Scroll Bars):
class MyTextArea extends TextArea {
#Override
protected void layoutChildren() {
super.layoutChildren();
ScrollBar scrollBarv = (ScrollBar) this.lookup(".scroll-bar:vertical");
if (scrollBarv != null) {
System.out.println("hiding vbar");
((ScrollPane) scrollBarv.getParent()).setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
}
ScrollBar scrollBarh = (ScrollBar) this.lookup(".scroll-bar:horizontal");
if (scrollBarh != null) {
System.out.println("hiding hbar");
((ScrollPane) scrollBarh.getParent()).setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
}
}
#Override
protected double computePrefWidth(double width) {
Bounds bounds = getTextBounds();
Insets insets = getInsets();
double w = Math.ceil(bounds.getWidth() + insets.getLeft() + insets.getRight());
return w;
}
#Override
protected double computePrefHeight(double height) {
Bounds bounds = getTextBounds();
Insets insets = getInsets();
double h = Math.ceil(bounds.getHeight() + insets.getLeft() + insets.getRight());
return h;
}
//from https://stackoverflow.com/questions/15593287/binding-textarea-height-to-its-content/19717901#19717901
public Bounds getTextBounds() {
//String text = (textArea.getText().equals("")) ? textArea.getPromptText() : textArea.getText();
String text = "";
text = this.getParagraphs().stream().map((p) -> p + "W\n").reduce(text, String::concat);
text += "W";
helper.setText(text);
helper.setFont(this.getFont());
// Note that the wrapping width needs to be set to zero before
// getting the text's real preferred width.
helper.setWrappingWidth(0);
return helper.getLayoutBounds();
}
}

Collecting data from People Picker

I want to Collect the usernames added in the PeoplePicker and display them in the textbox on the click of "Add" button for a custom aspx page.
I tried many codes but its not working.
Here is my code:
protected void btnpicker_Click(object sender, EventArgs e)
{
for (int i = 0; i < userPicker.ResolvedEntities.Count; i++)
{
PickerEntity picker = (PickerEntity)userPicker.ResolvedEntities[i];
Hashtable hstEntityData = picker.EntityData;
string accountName = Convert.ToString(hstEntityData["AccountName"]);
txtPicker.Text = "Count" + hstEntityData.Count.ToString();
txtPicker.TextMode = TextBoxMode.MultiLine;
}
}
Help Highly Appreciated.
Try the following code.
protected void btnpicker_Click(object sender, EventArgs e)
{
for (int i = 0; i < userPicker.ResolvedEntities.Count; i++)
{
PickerEntity picker = (PickerEntity)userPicker.ResolvedEntities[i];
yourTextBox.Text = "Count: " + new SPFieldUserValue(yourSPWebObject, Convert.ToInt32(picker.EntityData["SPUserID"]), picker.Key).User.Name;
}
}
This code will give all name of the users in your textbox.

J2me+images in form

I want to make the clock application where user enters the number in the textbox and click ok then user get the number at every 1 sec.
Example if user enter 5 then the timer start the display screen shows the number 1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,...so on.
Now i had taken form and text field for user to enter the number,then a timer which will change the number at every second.and 10 images of number (0-9).As i want to dispaly the number in very large size.Now i had implement this logic in below way:-
public class Clock extends MIDlet implements CommandListener {
public Command GO, Exit;
TextField TxtData;
protected Display display;
int number, counter;
Form form;
private Timer timer;
private TestTimerTask task;
boolean increment, time;
private StringItem s1 = new StringItem("", "");
Image image0;
Image image1;
Image image2;
Image image3;
Image image4;
Image image5;
Image image6;
Image image7;
Image image8;
Image image9;
Image[] secondAnimation;
protected void startApp() {
display = Display.getDisplay(this);
increment = true;
time = false;
form = new Form("Clock");
TxtData = new TextField("Number:-", "", 5, TextField.NUMERIC);
try {
image0 = Image.createImage("/images/0.png");
image1 = Image.createImage("/images/1.png");
image2 = Image.createImage("/images/2.png");
image3 = Image.createImage("/images/3.png");
image4 = Image.createImage("/images/4.png");
image5 = Image.createImage("/images/5.png");
image6 = Image.createImage("/images/6.png");
image7 = Image.createImage("/images/7.png");
image8 = Image.createImage("/images/8.png");
image9 = Image.createImage("/images/9.png");
secondAnimation = new Image[]{image0,image1,image2, image3, image4, image5, image6, image7, image8, image9};
} catch (IOException ex) {
System.out.println("exception");
}
GO = new Command("Go", Command.OK, 1);
Exit = new Command("Exit", Command.EXIT, 2);
form.append(TxtData);
form.append(s1);
form.addCommand(GO);
form.addCommand(Exit);
form.setCommandListener(this);
display.setCurrent(form);
}
protected void pauseApp() {
}
protected void destroyApp(boolean unconditional) {
timer.cancel();
notifyDestroyed();
}
public void commandAction(Command cmnd, Displayable dsplbl) {
String label = cmnd.getLabel();
if (label.equals("Go")) {
try {
System.out.println("txt==" + (TxtData.getString()));
if (!TxtData.getString().equalsIgnoreCase("")) {
counter = Integer.parseInt(TxtData.getString());
if (time) {
timer.cancel();
task.cancel();
}
number = 1;
timer = new Timer();
task = new TestTimerTask();
timer.schedule(task, 1000, 1000);
}
} catch (NumberFormatException ex) {
System.out.println("exception");
}
} else if (label.equals("Exit")) {
destroyApp(true);
}
}
private class TestTimerTask extends TimerTask {
public final void run() {
time = true;
s1.setText(""+ number);
if (counter < 10) {
form.append(secondAnimation[0]);
form.append(secondAnimation[0]);
form.append(secondAnimation[number]);
} else if (counter < 100) {
form.append(secondAnimation[0]);
form.append(secondAnimation[(number % 100) / 10]);
form.append(secondAnimation[(number % 10)]);
} else if (counter < 1000) {
form.append(secondAnimation[(number % 10)]);
form.append(secondAnimation[(number % 100) / 10]);
form.append(secondAnimation[(number / 100)]);
}
number++;
if (number == counter + 1) {
number = 0;
}
}
} }
But as the form goes on appending the image as timer moves it is not showing the desired output!
I had tried to do it through LWUIT but as i had user 10 .png files and adding LWUIT.jar file make the size of .jar file 557kb which is very heavy.
So i want to do it through normal forms only.
I cant use canvas as the keypad can vary like (touch,qwerty etc).So i need to do normal form or LWUIT only.Can anyone please help me for this.
I noticed you only append items but never remove - is that intended?
Also, did you try two different forms to animate instead of one? For simple test, say, fill them in parallel, just call setCurrent for one that is not displayed in the moment of update
//...
private void appendTwice(Image image) {
form1.append(image);
form2.append(image);
}
//...
public final void run() {
time = true;
s1.setText(""+ number);
if (counter < 10) {
appendTwice(secondAnimation[0]);
//...
}
display.setCurrent(number & 1 == 0 ? form1 : form2);
number++;
//...
}
//...

Resources