Changing Title font in chart using textbox #C - charts

After writing a Title in textbox and clicking a button, title changes,
How to change the title font as well?
private void button4_Click(object sender, EventArgs e)
{
string chartTitle;
try
{
chartTitle = textBox1.Text.ToString();
chart1.Titles.Clear();
chart1.Titles.Add(chartTitle);
//chartTitle.Font = new Font("Tahoma",11,FontStyle.Bold); (Not working)
}
catch
{
MessageBox.Show("Error!");
}
}

Related

clicking a button inside tab control/ tab page - revit form

i am trying too use a tabControl panel to put multiple features in a single form.
how can i make a button inside a tab clickable? it seems as if the button is not active when its being clicked from inside its parent tab.
how can i make the button active from inside the tab container?
notes:
i tryied to place a call for the button inside the tabPage, but then - when i clicked the button nothing happened, but when i clicked somewhere random inside the tab itself the button activity started.
buttons decleration + tabcontrol decleration:
// a button to add the associated views to the right listbox (listbox2):
private void button1_Click(object sender, EventArgs e)
{
listBox2.Items.Clear();
selectedItemText = listBox1.SelectedItem.ToString();
selectedItemIndex = listBox1.SelectedIndex;
foreach(Level lev in levels)
{
if(lev.Name == selectedItemText)
{
pickedLevel = lev;
}
}
foreach(Element view in views)
{
View v = view as View;
if (v.GenLevel != null)//check if the view is indeed a level
{
if (v.ViewType == ViewType.CeilingPlan && v.GenLevel.Name == pickedLevel.Name)//check if the plan is cielling, and if it has the same level as chosen
{
listBox2.Items.Add(v.Name);
}
}
}
dataBindings();
}
// set the listbox1 back:
private void dataBindings()
{
listBox1.DataSource = null;
listBox1.DataSource = levelNames;// string list
}
// button to clear the right listbox
private void button2_Click(object sender, EventArgs e)
{
listBox2.Items.Clear();
dataBindings();
}
// the tab decleration--> what goes here?
private void tabPage1_Click(object sender, EventArgs e)
{
}

Old Screen From Activity Gets Displayed When Back Button Used

I guess I do not understand how things like the "Back Button" affect how Activities behave.
Here is my main activity screen shot:
If the user clicks the bookmark icon in the upper right, my BookmarksActivity displays like so:
Here the user clicks the Add button to add the bookmark and I call finish() in my BookmarksActivity class and the screen returns to the my MainActivity ...
Now let's say the user wants to delete a bookmark, they would again click the bookmark icon which presents the user with this screen:
Now the user can click on the delete button resulting in this screen:
Now the user wants to get back to the MainActivity's screen by pressing the Back Button, doing so removes the keyboard as one would expect, resulting in this screen:
But now the user still wants to get back the main screen, so they click the Back Button again, but instead of the main screen one would expect to see they see this one!
Now there is no bookmark in my SQLite database yet one is being displayed. If the user clicks that back button again they do, finally, get the main activity screen ...
... and if they click on the Bookamrk icon you can see that there is no bookmark:
Thanks for bearing with me and that lengthy description of the problem. Here is what I believe to be the pertinent snippets of code:
Here's where the delete happens:
public class BookMarksBaseAdapter extends BaseAdapter {
...
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.bookmark, null);
TextView tv_bookmark_name = (TextView)vi.findViewById(R.id.bookmark_name);
TextView tv_bookmark_clock = (TextView)vi.findViewById(R.id.bookmark_clock);
Button deleteButton = (Button)vi.findViewById(R.id.btn_delete_bookmark);
final bookMark bookmark = new bookMark(data.get(position).get_bookmark_name(), data.get(position).get_bookmark_track(), data.get(position).get_bookmark_clock(), 0);
final String bookmark_name = bookmark.get_bookmark_name();
final int ibookmark_clock = bookmark.get_bookmark_clock();
// Setting all values in listview
tv_bookmark_name.setText(bookmark_name);
tv_bookmark_clock.setText(utils.milliSecondsToTimer(ibookmark_clock));
deleteButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d( TAG, "delete button clicked line 73" );
db.deleteBookmark(bookmark);
v.getContext().startActivity(new Intent(v.getContext(), com.redcricket.myApp.BookMarksActivity.class));
}
});
return vi;
}
And here is the an snippet from my BookmarkActivity onCreate method:
#Override
public void onCreate(Bundle savedInstanceState) {
currentChapterTitle = com.redcricket.myApp.MainActivity.getTrackTitle(0);
currentTrack = com.redcricket.myApp.MainActivity.getCurrentSongIndex();
currentTrackPosition = "00:00:00";
db = new Databasehandler(this);
db.getWritableDatabase();
utils = new Utils();
try {
currentChapterTitle = com.redcricket.myApp.MainActivity.getCurrentTrackTitle();
} catch (Exception e) {
Log.d( TAG, "expection line 27" );
e.printStackTrace();
}
try {
icurrentTrackPosition = com.redcricket.myApp.MainActivity.getCurrentTrackPosition();
currentTrackPosition = utils.milliSecondsToTimer(icurrentTrackPosition);
} catch (Exception e) {
Log.d( TAG, "expection line 34" );
e.printStackTrace();
}
super.onCreate(savedInstanceState);
setContentView(R.layout.bookmarks);
try {
new_bookmark_name = (EditText) findViewById(R.id.new_bookmark_name);
} catch (Exception e) {
Log.d( TAG, "expection line 43" );
e.printStackTrace();
}
try {
new_bookmark_name.setText( currentChapterTitle );
} catch (Exception e) {
Log.d( TAG, "expection line 49" );
e.printStackTrace();
}
try {
new_bookmark_clock = (TextView) findViewById(R.id.new_bookmark_clock);
} catch (Exception e) {
Log.d( TAG, "expection line 55" );
e.printStackTrace();
}
try {
new_bookmark_clock.setText( currentTrackPosition );
} catch (Exception e) {
Log.d( TAG, "expection line 61" );
e.printStackTrace();
}
try {
addButton = (Button) findViewById(R.id.btn_add_new_bookmark);
} catch (Exception e) {
Log.d( TAG, "expection line 43" );
e.printStackTrace();
}
addButton.setOnClickListener(this);
bookMarkList = db.getAllBookmarks();
// add list
bookmark_list=(ListView)findViewById(R.id.bookmarks_list);
adapter=new BookMarksBaseAdapter(this, bookMarkList, this);
bookmark_list.setAdapter(adapter);
I must be doing something wrong somewhere. I have tried to override the onBackButton method and have it call finish but that didn't help at all. My best guess is that this line in wrong:
v.getContext().startActivity(new Intent(v.getContext(), com.redcricket.myApp.BookMarksActivity.class));
I call that when the delete button get pressed.
Any help welcomed. Thanks!
I am assuming Main is one activity, book mark is another activity and book mark delete is another activity. Unless you tell an activity to have no history or explicitly finish it before going to another activity it will stay in the activity stack.
In your example the user goes MainActivity -> BookMarkActivty then back to MainActivity through on back pressed which removed BookMarkActivity from the stack. Its all good.
In your other example the user goes MainActivity -> BookMarkActivity -> DeleteActivity
the question here is when they click delete are you finishing DeleteActivty or starting a new BookMarkActivty?
It looks like you are starting a new BookMarkActivty, finished the old BookMarkActivity and ended up with a stack of Main - DeleteBookMark - BookMark after the deletion process.
Don't finish bookmark when they choose to do a delete and set the delete activity to have no history or explicitly finish it after delete.
Doh! I figured out what I needed to do. I need to save the Activity that gets passed to the constructor of my BookMarksBaseAdapter class as a private member like so ...
public class BookMarksBaseAdapter extends BaseAdapter {
private Activity activity;
...
BookMarksBaseAdapter (Activity a, ArrayList<bookMark> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
utils = new Utils();
db = new Databasehandler(a);
}
... then I call call activity.finish() when the delete button gets pressed like this ...
deleteButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
db.deleteBookmark(bookmark);
activity.finish();
}
});

How can I pass a listview from one form to another form?

I have 2 forms. form1 and form2. There is a button at form1 for me to access to form2 and in form2, I have a listview2 and some textboxes. I manage to input items into listview2. Then when I click on the OK button in form2, listview1 in form1 should show exactly like listview2. So guys, can anyone suggest me a way to do this? Thanks
Below are my codes. I hope I don't confuse you all.
Form1 code =>
namespace MainServerPage
{
public partial class MainServerPage : Form
{
public ListView LV;
public MainServerPage()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
AddItem Add = new AddItem(this); //to open form2
Add.ShowDialog();
}
}
}
Form2 code =>
namespace MainServerPage
{
public partial class AddItem : Form
{
MainServerPage currentform; //I learn this way of passing form to another but it's not working
public AddItem(MainServerPage incomingform)
{
currentform = incomingform;
InitializeComponent();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
ListViewItem item = new ListViewItem(txtCode.Text);
item.SubItems.Add(txtLocation.Text);
item.SubItems.Add(cbxStatus.Text);
item.SubItems.Add(txtWeatherHigh.ToString());
item.SubItems.Add(txtWeatherLow.ToString());
listView2.Items.Add(item); //send to listView2
txtCode.Text = "";
txtLocation.Text = "";
cbxStatus.Text = "";
txtWeatherHigh.Text = "";
txtWeatherLow.Text = "";
cbxZone.Text = "";
}
private void btnOk_Click(object sender, EventArgs e)
{
currentform.LV = load; //I got stuck here...do not know what to do
}
}
}
In general, it's not the list view you want to pass, it's the data that the list view is representing. You should probably rethink your design such that you btnUpdate_Click function builds a data object rather than building a ListViewItem directly. Then you can either pass the data object(s) back to your first form.

Silverlight 5 + AutoCompleteBox = Bug

Just installed SL5 and the toolkit, that were released few days ago.
The bug happens when you set the Text property of the AutoCompleteBox to string.Empty. It causes the AutoCompleteBox to be in a buggy state. To reproduce the bug:
add an AutoCompleteBox and a Button to the main page. Register to the TextChanged and Click events. This is the code-behind:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
auto.Text = string.Empty;
}
private void auto_TextChanged(object sender, RoutedEventArgs e)
{
// Put a break point here.
}
}
In runtime:
1) type "aa" into the autobox.
2) click the button.
3) type "q". ( TextChanged is still invoked).
4) erase the "q" - TextChanged is not invoked.
5) type "q" again - TextChanged is not invoked.
6) and so on, until you pick a new letter. And then it's starts over.
I found a workaround for this strange behavior. You need a control derived from AutoCompleteBox and overrride OnApplyTemplate method to find inner TextBox of AutoCompleteBox.
When inner TextBox TextChanged event fires you need to fire TextChanged event of AutoCompleteBox control manually.
public class CustomAutoComplete : AutoCompleteBox
{
TextBox mytext;
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
mytext = GetTemplateChild("Text") as TextBox;
mytext.TextChanged += new System.Windows.Controls.TextChangedEventHandler(mytext_TextChanged);
}
void mytext_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
this.Text = mytext.Text;
OnTextChanged(new RoutedEventArgs());
}
}

show modal popup from code behind

i have a dropdownlist
in codebehind,i have this function
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
///////
}
now i want to show modal popup when a particular text is selected from the dropdownlist from this function
if(DropDownList1.SelectedItem.Text.Equals("Some Text"))
{
ModalPopupExtender1.Show();
}