|
|
thanks Programm3r
I solved the issue by putting ProgressBar.Refresh() on top in the timer event before the text property of the progressbar gets changed. But before, I had put it in the bottom of timer and didn't work. Anyway, thanks for dealing.
|
|
|
|
|
I want to Serialize a Dictionary in Binary format but I get an error message telling that this objecto is not Serializable, is there any way of do it or I need to create my own dictionary class.
Regards
|
|
|
|
|
There is an article here on CP about serializing Dictionaries (amongst other things). Unfortunately, for you, it uses XML Serialization. In case it may offer you some clues, here is a link Yet Another XML Serialization Library for the .NET Framework[^]
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi all,
I found the following code, that allows one to write a string on a ProgressBar ... Only thing is that I can't get it to work Can anyone else make it work, and if so ... what am I doing wrong?
SetProgressBarText(progressBar1, null, ProgressBarTextLocation.Centered, Color.Black, SystemFonts.DefaultFont);
private void SetProgressBarText(System.Windows.Forms.ProgressBar Target,
string Text,
ProgressBarTextLocation Location,
System.Drawing.Color TextColor,
System.Drawing.Font TextFont
)
{
if (Target == null)
throw new ArgumentException("Null Target");
if (string.IsNullOrEmpty(Text))
{
int percent = (int)(((double)(Target.Value - Target.Minimum) / (double)(Target.Maximum - Target.Minimum)) * 100);
Text = percent.ToString() + "%";
}
using (Graphics gr = Target.CreateGraphics())
{
gr.DrawString(Text,
TextFont,
new SolidBrush(TextColor),
new PointF(
Location == ProgressBarTextLocation.Left ? 5 :
progressBar1.Width / 2 - (gr.MeasureString(Text,
TextFont).Width / 2.0F),
progressBar1.Height / 2 - (gr.MeasureString(Text,
TextFont).Height / 2.0F)));
}
}
public enum ProgressBarTextLocation
{
Left,
Centered
}
Many thanks in advance
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
|

public class ProgressLabel: ProgressBar {
private static StringFormat sfCenter = new StringFormat() {
Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
private Color textColor = DefaultTextColor;
private string progressString;
public ProgressLabel() { SetStyle(ControlStyles.AllPaintingInWmPaint, true); }
protected override void OnCreateControl() {
progressString = null;
base.OnCreateControl();
}
protected override void WndProc(ref Message m) {
switch(m.Msg) {
case 15: if(HideBar) base.WndProc(ref m);
else {
ProgressBarStyle style = Style;
if(progressString == null) {
progressString = Text;
if(!HideBar && style != ProgressBarStyle.Marquee) {
int range = Maximum-Minimum;
int value = Value;
if(range > 42949672) { value = (int)((uint)value>>7); range = (int)((uint)range>>7); }
if(range > 0) progressString = string.Format(progressString.Length == 0 ? "{0}%" : "{1}: {0}%",
value*100/range, progressString);
}
}
if(progressString.Length == 0) base.WndProc(ref m);
else using(Graphics g = CreateGraphics()) {
base.WndProc(ref m);
OnPaint(new PaintEventArgs(g, ClientRectangle));
}
}
break;
case 0x402: goto case 0x406;
case 0x406: progressString = null;
base.WndProc(ref m);
break;
default:
base.WndProc(ref m);
break;
}
}
protected override void OnPaint(PaintEventArgs e) {
Rectangle cr = ClientRectangle;
RectangleF crF = new RectangleF(cr.Left, cr.Top, cr.Width, cr.Height);
using(Brush br = new SolidBrush(TextColor))
e.Graphics.DrawString(progressString, Font, br, crF, sfCenter);
base.OnPaint(e);
}
public bool HideBar {
get { return GetStyle(ControlStyles.UserPaint); }
set { if(HideBar != value) { SetStyle(ControlStyles.UserPaint, value); Refresh(); } }
}
public static Color DefaultTextColor {
get { return SystemColors.ControlText; }
}
public Color TextColor {
get { return textColor; }
set { textColor = value; }
}
public override string Text {
get { return base.Text; }
set { if(value != Text) { base.Text = value; progressString = null; } }
}
public override Font Font {
get { return base.Font; }
set { base.Font = value; }
}
}
|
|
|
|
|
Thanks firda, been looking for that code all over.
|
|
|
|
|
how to use the same macro of excel in c#
Private Sub Worksheet_Activate()
Range("A1").Select
End Sub
|
|
|
|
|
|
the problem is im having a xls file and im opening it using workbook.open() and i select cell A10 and close it next time when i open the file i want the focus back on A1. i.e always the file is open the focus should be on cell A1 for that i used the macro which i stated in the previos thread. but i feel it would be better if i can do that also in the application.
below is the code
private void button1_Click(object sender, EventArgs e)
{
openexcel();
}
private static void openexcel()
{
Excel.Application xlApplication = new Excel.Application();
Excel.Workbooks xlBooks;
Excel.Worksheet xls;
xlBooks = xlApplication.Workbooks;
xlBooks.Open(Application.StartupPath + @"\ExcelFile01.xls", Type.Missing, false, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing);
xls = xlApplication.ActiveWorkbook.Worksheets[2] as Excel.Worksheet;
xls.Visible = Excel.XlSheetVisibility.xlSheetHidden;
xls = xlApplication.ActiveWorkbook.ActiveSheet as Excel.Worksheet;
xls.Rows.AutoFit();
//todo
focus back to cell A1
xlApplication.Visible = true;
System.Runtime.InteropServices.Marshal.ReleaseComObject(xls);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApplication);
}
|
|
|
|
|
Hi,
Wouldn't something like Cells(YourRow,YourColumn).Select work?
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Have a look Developers Guide to the Excel 2007 Application Object[^], most of it is in VB.NET, but that's just syntax ....
I'm sure that you'll find something useful there ....
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Is this going to be the same excel file you'll be opening every time? You could put an 'AutoOpen' macro in the excel file (which would run anytime the file is opened, just enable macros when you open it) to do all this preliminary stuff you're doing in C#. It would be much easier in VBA anyway.
The Code Demon Rises.
|
|
|
|
|
This should do it: Range.Activate Method[^] (Activates a single cell, which must be inside the current selection. To select a range of cells, use the Select method.)
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Hi guys!
Maybe someone can help me with this:
I have a library C which controls a device and it's methods take enumerations as parameters.
Then I have a library B which references C and "wraps" the complex commands from library C in something useful and maintainable.
The last thing I have is an assembly A which does the UI stuff. It references ONLY library B.
Nevertheless B needs the values of the enumerations of C to control the device (and to fill comboboxes with the enum-Values)
I need a way to pass the information, which value of an enumeration is needed from A to B.
I do not want to reference C in A (that's how I would get the enumerations as well).
Which would be a good approach to solve this problem.
Help would really be appreciated!
|
|
|
|
|
You could just copy 'n paste the enum .. but that makes it harder to add/change values later (there are probably better solutions..)
|
|
|
|
|
Why not reference C in A? If B references C and A references B, then you have to distribute C with application A anyway. If you want A to have access to the values of the enumeration, referencing C is the 'right' and easiest way to go about it.
|
|
|
|
|
Thanks for your reply. I just hoped it would be possible to separate the C2 logic from the UI with the lib B as link.
|
|
|
|
|
I would put the enum in A; but you could put the enum in D.
|
|
|
|
|
Thanks for the hint, unfortunately I can't do this due to he fact, that lib C wasn't written by me.
|
|
|
|
|
Then write your own in B, and then translate.
|
|
|
|
|
Hi there,
I am quite new to C# and WPF especially. I have a form, with 2 listboxes on. The first looks up an xml file and gets some data items (themes), the next listbox is bound to the first, and gets some data (scenes) from inside the selected theme tag.
This works wonderfully.
I would now like to get the value of an element (FreeStyleCue) and use that in a c# function tied to the OnSelectionChanged handler.
However I cant work out for the life of me how to get the information from the FreeStyleCue tag.
Can anyone help me??
Here is the xml file.
<?xml version="1.0" encoding="utf-8" ?><br />
<themes><br />
<theme name="Yellow" description="A yellow theme" order="1"><br />
<scene name="PreShow" order ="1"><br />
<description>For before the show yellow.</description><br />
<FreeStyleCue>y12</FreeStyleCue><br />
</scene><br />
<scene name="Scenex" order ="1"><br />
<description>During yellow show</description><br />
<FreeStyleCue>y122</FreeStyleCue><br />
</scene><br />
</theme><br />
<theme name="Blue" description="A blue theme" order="1"><br />
<scene name="PreShow" order ="1"><br />
<description>For before the show</description><br />
<FreeStyleCue>b12</FreeStyleCue><br />
</scene><br />
<scene name="Scene1" order ="1"><br />
<description>During Show</description><br />
<FreeStyleCue>b122</FreeStyleCue><br />
</scene><br />
</theme><br />
</themes><br />
Here is the WPF XAML file
<Window x:Class="WpfApplication1.Window1"<br />
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />
Title="Window1" Height="400" Width="800"><br />
<Window.Resources><br />
<br />
<XmlDataProvider x:Key="AllThemes" XPath="themes" Source="testdata.xml" /><br />
<br />
<br />
<DataTemplate x:Key="dtThemes"><br />
<br />
<StackPanel FlowDirection="LeftToRight" Orientation="Vertical"><br />
<br />
<TextBlock Text="{Binding XPath=@name}" FontSize="15" /><br />
<TextBlock Text="{Binding XPath=@description}" /><br />
<br />
</StackPanel><br />
<br />
</DataTemplate><br />
<br />
<br />
<DataTemplate x:Key="dtScenes"><br />
<StackPanel FlowDirection="LeftToRight" Orientation="Vertical"><br />
<br />
<TextBlock Text="{Binding XPath=@name}" FontSize="15" /><br />
<TextBlock Text="{Binding XPath=description}" /><br />
<TextBlock Text="{Binding XPath=FreeStyleCue}" /><br />
<br />
</StackPanel><br />
</DataTemplate><br />
<br />
<br />
<br />
</Window.Resources><br />
<br />
<br />
<br />
<Grid Name="gMain"><br />
<Grid.ColumnDefinitions><br />
<ColumnDefinition Width="123" /><br />
<ColumnDefinition Width="8"/><br />
<ColumnDefinition Width="*" /><br />
</Grid.ColumnDefinitions><br />
<br />
<Menu Grid.Column="0" Grid.ColumnSpan="3"></Menu><br />
<br />
<ListBox Name="listboxTheme" <br />
ItemsSource="{Binding Source={StaticResource AllThemes}, XPath=theme}"<br />
ItemTemplate="{StaticResource dtThemes}" HorizontalAlignment="Left" Width="123"><br />
</ListBox><br />
<br />
<GridSplitter Grid.Column="1"></GridSplitter><br />
<br />
<StackPanel Grid.ColumnSpan="2" Margin="6,0,6,0" Grid.Column="1"><br />
<ListBox Name="listboxScenes" <br />
ItemsSource="{Binding ElementName=listboxTheme, Path=SelectedItem, UpdateSourceTrigger=PropertyChanged}" <br />
ItemTemplate="{StaticResource dtScenes}" Height="650" SelectionChanged="listboxScenes_SelectionChanged"><br />
<br />
</ListBox><br />
</StackPanel><br />
<br />
</Grid><br />
</Window><br />
and the code that is asking for the data
<br />
private void listboxScenes_SelectionChanged(object sender, SelectionChangedEventArgs e)<br />
{<br />
<br />
<br />
SelectQueueInFS(SelectionID);
}<br />
<br />
|
|
|
|
|
I give u an example.
I have a ComboBox 'themesComboBox' decalared in XAML file. (Note the x:Name, instead of Name, so that we can refer the ComboBox from C#).
<ComboBox SelectedIndex="0" x:Name="themesComboBox" SelectionChanged="ThemeChanged">
The following is the method which handles the event.
void ThemeChanged(object sender,RoutedEventArgs args)
{
ComboBoxItem cbi =(ComboBoxItem)themesComboBox.SelectedItem;
string themeName = cbi.Content.ToString();
}
Modify the two lines in your program
<TextBlock Text="{Binding XPath=FreeStyleCue}" /> to
<TextBlock Text="{Binding XPath=FreeStyleCue}" x:Name='freeStyeleCueTextBox'/>
<ListBox Name="listboxScenes"
ItemsSource="{Binding ElementName=listboxTheme, Path=SelectedItem, UpdateSourceTrigger=PropertyChanged}"
ItemTemplate="{StaticResource dtScenes}" Height="650" SelectionChanged="listboxScenes_SelectionChanged"> to
<ListBox x:Name="listboxScenes"
ItemsSource="{Binding ElementName=listboxTheme, Path=SelectedItem, UpdateSourceTrigger=PropertyChanged}"
ItemTemplate="{StaticResource dtScenes}" Height="650" SelectionChanged="listboxScenes_SelectionChanged">
Now you can access the textbox and list box from your c# code.
Hope it will help you.
|
|
|
|
|
Hi there,
Thanks for the help. Most appreciated!
THe only thing is that I was using XML in the listbox so it outputs XML instead of a string.
I have included
using System.Xml;
and then the code is now
XmlNodeList FSQUES = ((XmlElement)listboxScenes.SelectedItem).GetElementsByTagName("FreeStyleCue");<br />
<br />
foreach (XmlNode FreeStyleCue in FSQUES)<br />
{<br />
SelectQueueInFS(FreeStyleCue.InnerText);<br />
<br />
}
Hope this helps someone.
Reg
|
|
|
|
|