WPF C# Circle Progress Bar WindowsFormsHost - c#

So I'm getting a weird error... I followed some steps to create a CircularProgressBar in my WPF C# App. It works fine on my desktop, it doesn't on my laptop.
I create a WindowsFormsHost and make the Circular Progress Bar the Child. I then make it the children of a grid called ProgressGrid.
Anyway, The error just says "Unhandled exception has occured in a component in your application. If you click Continue, the application will ignore this error" It runs perfectly fine if I click continue mind you.
The error details say "System.ArgumentException: Parameter is not valid" it goes on to list pretty much everything I wrote. I thought it had something to do with Dispose()... Heres the Code:
var SelectAll =
(from a in dc.GetTable<SR>()
select a).ToList();
int all = SelectAll .Count();
var ByGroup =
(from a in dc.GetTable<SR>()
where a.GroupID == GroupID
orderby a.ID
select a).ToList();
int SelectedGroup = ByGroup .Count();
System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
CircularProgressBar.CircularProgressBar ProgressCircle = new CircularProgressBar.CircularProgressBar();
host.Child = ProgressCircle;
ProgressGrid.Children.Add(host);
if (ShallMarquee == 1 || FilterByThisDivision == TheEmployee.Division)
{
ProgressCircle.Style = System.Windows.Forms.ProgressBarStyle.Marquee;
}
else
{
ProgressCircle.Style = System.Windows.Forms.ProgressBarStyle.Blocks;
}
ProgressCircle.MarqueeAnimationSpeed = 4000;
ProgressCircle.Text = Convert.ToString(NumOf + "%");
ProgressCircle.SubscriptText = "";
ProgressCircle.SuperscriptText = "";
ProgressCircle.Font = new Font("Arial", 22);
ProgressCircle.ProgressWidth = 10;
ProgressCircle.SuperscriptColor = System.Drawing.Color.Black;
ProgressCircle.ProgressColor = System.Drawing.ColorTranslator.FromHtml(MainColor);
System.Windows.Media.Color StandardBackgroundBlue = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(BackgroundColor);
var drawingcolor = System.Drawing.Color.FromArgb(StandardBackgroundBlue.A, StandardBackgroundBlue.R, StandardBackgroundBlue.G, StandardBackgroundBlue.B);
ProgressCircle.BackColor = drawingcolor;
ProgressCircle.InnerColor = drawingcolor;
ProgressCircle.OuterColor = System.Drawing.Color.LightGray;
ProgressCircle.ForeColor = System.Drawing.Color.Black;
ProgressCircle.Value = NumOf;
ProgressCircle.Maximum = TotalNum;
//END CIRCLE
For now the gridjust displays a string as the number while I adjust things so you can ignore that. I also read something about GDI but I'm a bit lost.
P.S. I should note it also says "Invalid Parameter" which it most certainly is not.
P.P.S. I developed this on a Windows 7 64 bit. My laptop is a Windows 10 64bit. But it also doesn't work on my brothers Windows 7 64 bit. If that helps any...

Okay, so I was able to make it work. I'm not "exactly" sure why though. I loaded the grid that contains the WindowsFormsHost Grid with visibility set to false first and after it loaded I set it to true. For whatever reason, it works this way. If anyone could think of why that would be awesome. This way does work though!

Related

Gtk# application is not rendering TreeView Properly

I am trying to develop a gtk application on mac using gtk#. I created a tree view just like in the tutorial but the arrows are not rendering properly as seem below, there are no arrows. I can click to open and close but the actual arrows aren't working.
I copy pasted the code from the tutorial and It did the same thing, but here is my code anywhere. I have also verified view.ShowExpanders is set to true
Application.Init();
Window window = new Window("Editor Window");
window.SetPosition(WindowPosition.Center);
window.HeightRequest = 800;
window.WidthRequest = 1200;
TreeView view = new TreeView();
view.WidthRequest = 500;
TreeViewColumn column = new TreeViewColumn();
column.Title = "Heirarchy";
CellRendererText cell = new CellRendererText();
column.PackStart(cell, true);
view.AppendColumn(column);
column.AddAttribute(cell, "text", 0);
TreeStore store = new TreeStore(typeof(string));
TreeIter i = store.AppendValues("Project");
i = store.AppendValues(i,"Room1");
i = store.AppendValues(i, "Item");
store.AppendValues(i, "Attribute");
store.AppendValues(i, "Attribute");
store.AppendValues(i, "Attribute");
view.ShowExpanders = true;
view.Model = store;
view.ShowExpanders = true;
window.Add(view);
window.DeleteEvent += ExitWindow;
window.ShowAll();
Application.Run();
Is there some sort of image asset that doesn't exist on my computer? How would I install that on mac? Thank you for any help you can provide.
As a comment suggested, using brew install adwaita-icon-theme fixed the problem

Why my columns dissapear? How to reorder columns in code in c#?

I have very strange problem in Visual Studio. I created grid on my windows form with 10 columns.
Everything works fine until I reordered the columns - all columns disappear!
I click undo, it gives back to me only 6 columns.
When I want to add 4 columns that are missing, the program throw error: This column already exist(or something like that). Then I have to get the latest version (I checked in before) to get all columns back. When I change anything in grid, same error happens every time. I tried to delete grid and make new one - same error. I even tried to delete WF and make new one - same error.
Any idea why is this happening?
Any idea how to reorder columns in code and bypass this strange error?
Best way is to control the code and not the same assistant you are doing.
To do this use the following example:
if (dataGridView1.DataSource != null)
{
dataGridView1.Columns["idColumn1"].HeaderText = "Text 1";
dataGridView1.Columns["idColumn1"].Width = 60;
dataGridView1.Columns["idColumn1"].Index = 0;
dataGridView1.Columns["idColumn2"].HeaderText = "Text 2";
dataGridView1.Columns["idColumn2"].Width = 60;
dataGridView1.Columns["idColumn2"].Index = 1;
dataGridView1.Columns["idColumn3"].HeaderText = "Text 3";
dataGridView1.Columns["idColumn3"].Width = 60;
dataGridView1.Columns["idColumn3"].Index = 2;
dataGridView1.Columns["idColumn4"].Visible= false;
dataGridView1.Columns["idColumn5"].Visible= false;
dataGridView1.Columns["idColumn6"].Visible= false;
}
I know that the main problem is not resolved, but if somebody have same error, you can reorder your columns in code like this:
private void TransakcijaZaFakturisanje_Load(object sender, EventArgs e)
{
gridTransakcijaZaFakturisanje.Columns["SifraTransakcije"].DisplayIndex = 0;
gridTransakcijaZaFakturisanje.Columns["Opis"].DisplayIndex = 1;
gridTransakcijaZaFakturisanje.Columns["SifraKomitenta"].DisplayIndex = 2;
gridTransakcijaZaFakturisanje.Columns["IdUgovor"].DisplayIndex = 3;
gridTransakcijaZaFakturisanje.Columns["IdUsluga"].DisplayIndex = 4;
gridTransakcijaZaFakturisanje.Columns["VaziOd"].DisplayIndex = 5;
gridTransakcijaZaFakturisanje.Columns["VaziDo"].DisplayIndex = 6;
//and so on...
}
I will continue to research the problem, if I find something usefull I will type it here. Thank you all for your support!

How to change window background color in mono (GTK)?

I have a window in gtk which includes a Build() function as follow:
protected virtual void Build()
{
global::Stetic.Gui.Initialize(this);
// Widget Client.Forms.Notification
this.Name = "Client.Forms.Notification";
this.Title = "Notification";
this.TypeHint = Gdk.WindowTypeHint.Normal;
//this.TypeHint = ((global::Gdk.WindowTypeHint)(4));
this.WindowPosition = ((global::Gtk.WindowPosition)(4));
// Container child Client.Forms.Notification.Gtk.Container+ContainerChild
this.vbox1 = new global::Gtk.VBox();
this.vbox1.Name = "vbox1";
this.vbox1.Spacing = 6;
// Container child vbox1.Gtk.Box+BoxChild
this.label1 = new global::Gtk.Label();
this.label1.HeightRequest = 20;
this.label1.Name = "label1";
this.label1.LabelProp = "Notification";
this.vbox1.Add(this.label1);
global::Gtk.Box.BoxChild w1 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.label1]));
w1.Position = 0;
w1.Expand = false;
w1.Fill = false;
// Container child vbox1.Gtk.Box+BoxChild
this.hbox1 = new global::Gtk.HBox();
this.hbox1.Name = "hbox1";
this.hbox1.Spacing = 6;
// Container child hbox1.Gtk.Box+BoxChild
this.image1 = new global::Gtk.Image();
this.image1.Name = "image1";
this.image1.Pixbuf = global::Gdk.Pixbuf.LoadFromResource("Client.Resources.icon.png");
this.hbox1.Add(this.image1);
global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.image1]));
w2.Position = 0;
w2.Expand = false;
w2.Fill = false;
// Container child hbox1.Gtk.Box+BoxChild
this.label2 = new global::Gtk.Label();
this.label2.Name = "label2";
this.label2.WidthRequest = 260;
this.label2.Wrap = true;
this.label2.LabelProp = "Description";
this.hbox1.Add(this.label2);
global::Gtk.Box.BoxChild w3 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.label2]));
w3.Position = 1;
w3.Expand = false;
w3.Fill = false;
this.vbox1.Add(this.hbox1);
global::Gtk.Box.BoxChild w4 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.hbox1]));
w4.Position = 1;
w4.Expand = false;
w4.Fill = false;
this.label1.ModifyBase(Gtk.StateType.Normal, Core.fromColor(System.Drawing.Color.Orange));
this.ModifyBase(Gtk.StateType.Normal, Core.fromColor(System.Drawing.Color.Orange));
this.vbox1.ModifyBase(Gtk.StateType.Normal, Core.fromColor(System.Drawing.Color.Orange));
root = new Gtk.EventBox();
root.Add(this.vbox1);
this.Decorated = false;
this.Add(root);
if ((this.Child != null))
{
this.Child.ShowAll();
}
this.DefaultWidth = 460;
this.DefaultHeight = 220;
}
(source code of this whole window: https://github.com/pidgeonproject/pidgeon/blob/master/Forms/Notification.cs)
As you can see it is calling
this.ModifyBase(Gtk.StateType.Normal, Core.fromColor(System.Drawing.Color.Orange));
which should change the background to orange, however it doesn't.
I tried to insert more similar functions on window elements, but it doesn't work either, does anyone know how to change the background color of the window?
What I want to do is create a small window with no decoration (so just a rectangle) of specific color and some text in it. This window is supposed to be transparent (that works now) and should have a picture and 2 labels with text and disappear on click - all this works now just I can't change the background from gray to some better color. I would be happy for answers that would let me do this using some other way (I can think of creating a small form just with drawing area and paint it with the color and then paint the text as well, but it sounds to me quite complicated for something so simple as I want to do).
NOTE: mono is using GTK 2, and the version of GTK# for .Net is using 2.12.20
Try to use Event Box. Seems to work
For GTK+2 you need to create a gtk resource like so:
char *my_custom_style = "style \"my-style-name\" { bg[NORMAL] = \"#339933\" }\nclass \"GtkWindow\" style \"my-style-name\"";
then load the resource when you start the program, after initialization:
gtk_rc_parse_string (my_custom_style);
Now any GtkWindow will use your custom style for it's background.
The C documentation for Gtk Resource Files
Edit:
If you only want to change one specific window, then you'd change the custom style string to something like
char *my_custom_style="style \"my-style-name\" { bg[NORMAL] = \"#339933\" }\nwidget \"my-custom-window\" style= \"my-style-name\"';
You then set the name of the window you want to change the background with
gtk_widget_set_name (GTK_WIDGET (my_window), "my-custom-window");
Edit 2:
Here's the documentation to the Gtk# Rc parsing function:
http://buttle.shangorilla.com/1.1/handlers/monodoc.ashx?link=M%3aGtk.Rc.Parse(System.String)
The documentation (for the C API) says that gtk_widget_modify_color() is deprecated, and that newly written code should use gtk_widget_override_background_color() instead, so try that.
Overriding themes in GTK+ is notoriously hard though, but the 3.0 API really sounds as if it's supporting what you want to do.
Can't test this myself at the moment, unfortunately.

How to hand code people picker in sharepoint 2010 for Coded UI

I am trying to automate sharepoint 2010 people picker, but it is very difficult even to highlight any control inside the window.
I have used hand coding to find the window but the controls inside the window are not highlighting.
WinWindow pp = new WinWindow(browserWindow);
pp.TechnologyName = "MSAA";
pp.SearchProperties[WinWindow.PropertyNames.ClassName] = "Internet Explorer_TridentDlgFrame";
pp.SearchProperties[WinWindow.PropertyNames.ControlType] = "Window";
pp.SearchProperties[WinWindow.PropertyNames.Name] = "Select People -- Webpage Dialog";
pp.Find();
pp.DrawHighlight();
Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument doc = new Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument(pp);
doc.TechnologyName = "Web";
doc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.TagName] = "BODY";
doc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.FrameDocument] = "False";
doc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.RedirectingPage] = "False";
doc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.ControlType] = "Document";
doc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.Title] = "Select People";
doc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.PageUrl] = PAGE_URL_Here;
doc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.AbsolutePath] = AbsolutePath_Here;
doc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.ClassName] = "HtmlBody";
doc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.FriendlyName] = "Select People";
doc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.HasFocus] = "False";
doc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.Exists] = "True";
doc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.Enabled] = "True";
doc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.IsTopParent] = "False";
doc.Find();
doc.DrawHighlight();
Above code easily highlights people picker window and used this object to find the control inside it is not finding any.
It is showing this error...
The playback failed to find the control with the given search properties. Additional Details:
TechnologyName: 'Web'
TagName: 'BODY'
FrameDocument: 'False'
RedirectingPage: 'False'
ControlType: 'Document'
Am i doing it right.
I found the answer for this,..
Well using crosshair or recording show the control on peoplepicker as separeate control but while finding through code all the control in it are shown as Edit box.
so need to store all control in a UITestControlCollection and use loop to find the control needed using its name property.
Then do the mouse or keyboard action.
//write ur code here to find the parent control
UITestControlCollection controlFound = matching.FindMatchingControls();
//use loop to find the control

WinForms Dynamic Label

I am creating dynamic labels and letting users change attributes of the labes like backcolor and so by sending unicode. However I don't know how to check if the label exists therefore I can't manipulate the dynamicly created label. below is my code:
if ((InputBox.Text.StartsWith("π")) && (InputBox.Text.EndsWith("}")))// only process if the message starts with π and ends with }
{
string Message = InputBox.Text;
InputBox.Text = "";// Clear the box when done.
// Butt1 message line
if (Message.StartsWith("πlabelt1"))
{
if (Message.StartsWith("πlabelt1_BackColor"))
{
Message = Message.Substring(19);
//labelt1.BackColor = System.Drawing.Color.FromName(Message.Replace("}", ""));
}
}
private void ImageBox_DragDrop(object sender, DragEventArgs e)
{
//Graphics g = ImageBox.CreateGraphics();
//g.DrawImage((Image)e.Data.GetData(DataFormats.Bitmap),
//new Point(e.X - this.Left, e.Y - this.Top - 150));
Point p2 = PointToClient(Cursor.Position);
Label buttlbl_ = new Label();
labelCount++;
buttlbl_.Name = "labelt" + labelCount.ToString();
buttlbl_.Location = new Point(p2.X, p2.Y);
buttlbl_.Size = new System.Drawing.Size(37, 37);
buttlbl_.BackColor = System.Drawing.Color.DarkGray;
this.Controls.Add(buttlbl_);
buttlbl_.BringToFront();
ImageBox.Invalidate();
}
}
Any suggestions?
you may set buttlbl_ as a class member so you can check if it is created
before creation you can find it in this.Controls collection (by id)
I think you've approached this problem incorrectly. You are apparently trying to offer the user an opportunity to edit these textboxes using a language-based interface. You either need to build a full parser to help you here or to look at an alternative paradigm, perhaps following the same approach that VS uses to allow you to create and edit labels via a GUI-type interface. That way you can maintain a tighter control over the actions that can be completed without the complexity of 'natural' language parsing.

Categories