C#/WinForms tooltip stops displaying - c#

I'm facing the following issue during setting up tooltips on a WinForms / C# desktop application (using .NET Framework version 4.5).
Application has hundreds of form elements where I would like to display a tooltip.
Current implementation as the following:
I have one toolTip object on my main form
Language file has been loaded and saved in an array
There is a method which suppose to assign the tooltip texts to the different elements accordingly by calling the SetToolTip method on the toolTip object.
E.g.
toolTip.SetToolTip(backBtn, LocalizationFile[0]);
toolTip.SetToolTip(myTextBox, LocalizationFile[1]);
It works fine, tooltips are displayed correctly.
As soon as I reach ca. 30 calls it stops working.
Calling ~30 times SetToolTip method to setup the required tooltips, cause to completely stop displaying the tooltips.
The previously worked tooltip texts are not getting display anymore.
There is no exception or any error message.
Can you please explain me why the toolTip object just stops displaying the texts after calling the SetToolTip method several times? Is there any workaround out there to apply in such cases?
EDIT-1
Following workaround works, but I'm still unsure what is the original problem.
I have created a method to call SetToolTip on the toolTip object, after calling the method, I re-create the toolTip instance using the "new" operator. That solves the issue. However as I want to disable anytime the tooltips on my application I also store all the references in a List. On that list I can iterate over to enable / disable all toolTip references according to what the user wants.
Basically there is a button to toggle the tooltips.
Do you have any idea, why this actually solves the original issue?
List<ToolTip> storeToolTipReferences = new List<ToolTip>(); //store tooltip references
//method begin called to set the tooltip on a control, store the reference of the tooltip and create a new instance
private void SetMyToolTip(Control ctrl, string toolTipText)
{
toolTip.SetToolTip(ctrl, toolTipText);
storeToolTipReferences.Add(toolTip);
toolTip = new ToolTip();
}
//called as the application loads or the user changes the language
private void SetAppLanguage(string[] LocalizationText)
{
storeToolTipReferences.ForEach(e => e.RemoveAll());
SetMyToolTip(ctrl1, LocalizationText[1]);
SetMyToolTip(ctrl2, LocalizationText[2]);
SetMyToolTip(ctrl3, LocalizationText[3]);
.....
}
//logic for tooltip enable/disable in my application
storeToolTipReferences.ForEach(t => t.Active = tooltip_control.Checked);
Thank you!

Related

TreeView node icon changes when selected only on custom icons in C#

So I have a TreeView in C# and I'm loading icons for folders via P/Invoke. It's working, but on icons which are custom (so to speak), they change to some weird icon, as seen in the image below:
On "Regular" folders, i.e. ones without custom icons, this doesn't happen. Also on things like my HDD icons, it doesn't happen. This is the code I'm using to set the icon key
ImageKey = node.FileInfo.UniqueIcon;
SelectedImageKey = ImageKey;
As you can see, there's no way SelectedImageKey is different from ImageKey. However, the icon is still being set as the 0th index of the ImageList.I have confirmed via the debugger that the keys are staying the same, after the object is added.
So any ideas why this would be happening only for some icons?
Thanks.
Update
I found a workaround, but I'm not calling it a solution. If I add this to my code:
private void FolderTree_BeforeSelect(object sender, TreeViewCancelEventArgs e) {
e.Node.SelectedImageKey = e.Node.ImageKey;
}
I'm not calling it a solution, because that command only has to run once for it to work. I know that because if I put it on the AfterExpand event, then after it does it for one bad one, all the others work after that, even before they're expanded. So it's like something just isn't clicking until after, and resetting just one makes all others work.

Triggering WinForm_Load() with a User Control nested in a Split Container

I'm currently working on a "Settings" screen for a project and want to implement a view similar to that found in Visual Studio, where there is a TreeView with a list of options and clicking on one of these options will load a UserControl in an adjacent panel in the same form. I am using a SplitContainer to group these two controls.
I thought that the Load event for the User Control would be triggered when it was displayed in the panel, but this is not the case. I also tried to trigger the Enter event but it still did not work so I tried to call a function when the form was initialized using the following method.
ViewSecurity newViewSecurity = new ViewSecurity(Globals._connectionString);
// This creates a new instance of the ViewSecurity form from within the TreeView.
And this is the code in the initializing function for the User Control
public ViewSecurity(string _cString)
{
InitializeComponent();
connectionString = _cString;
MessageBox.Show("Test");
populateData();
}
This method does not work either - the MessageBox does not show up and the function populateData() isn't called either. Any advice on how I could achieve what I am trying to do?
Thanks in advance!

Telerik Reporting: Adding Textbox at Runtime Does Not Show Up

I'm currently working on a report using Telerik Reporting (release Q1 2013), and I'm attempting to add a textbox at runtime to a header (and eventually the detail section as well), but the issue is the textbox that gets added does not show up. I'm not sure why it's not displaying, but there are no errors that occur after it is added. Right now I'm trying to add it during the itemdatabinding event. My code is below:
public partial class _WellPlateReport : Telerik.Reporting.Report
{
public _WellPlateReport(Dictionary<string, object> ReportParameters)
{
//
// Required for telerik Reporting designer support
//
InitializeComponent();
tbGenotype.Visible = false;
//
// TODO: Add any constructor code after InitializeComponent call
//
}
private void labelsGroupHeaderSection_ItemDataBinding(object sender, EventArgs e)
{
string temp = "";
Telerik.Reporting.Processing.GroupSection headerGroup = (Telerik.Reporting.Processing.GroupSection)sender;
Telerik.Reporting.TextBox tb = new Telerik.Reporting.TextBox();
tb.Left = new Telerik.Reporting.Drawing.Unit(0.5, UnitType.Inch) + tbGenotype.Left + tbGenotype.Width;
//tb.Width = new Telerik.Reporting.Drawing.Unit(3.0, UnitType.Inch);
tb.Size = tbSex.Size;
tb.Name = "TestLabel1";
tb.Value = "Test Label";
tb.Location = new Telerik.Reporting.Drawing.PointU(tbGenotype.Left + tbGenotype.Width + new Telerik.Reporting.Drawing.Unit(0.5, UnitType.Inch), Telerik.Reporting.Drawing.Unit.Inch(0D));
//this.labelsGroupHeaderSection.Items.Add(tb);
//this.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { tb });
this.labelsGroupHeaderSection.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { tb });
}
}
The tbGenotype is another textbox that the new textbox will be added next to at runtime, so i'm using the positioning of that to place the dynamic textboxes. There is an unknown number of additional columns that will need to be added, but I'm not sure why this isn't working. My searches showed others adding controls in a similar way.
Update: Also note, that the textbox tbGenotype was added in the designer in visual studio. Trying to set the visible property on that works, but adding the textbox to the header does not.
Try to look at this documentation. The only difference that I noticed was that they are adding the textbox to a panel. Then they are adding panel to the report. Check if tbGenotype is added in a panel or not but I think that every element you put in a report has to be in same panel first.
I have the same problem, but I notice when I refresh the report with the refresh button inside the report viewer (in my windows application; should be the same for the web version), the dynamically added controls show up. When I refresh a second time, an additional (second) set of controls shows up.
My observation is this: on initial run, the controls are added, but not visible (regardless of the visible property value being true). On first refresh (second server/application run), a second set of controls is added, not visible, and the first set is now visible. On the second refresh / third run, a third set of not visible controls is added, and the first 2 sets of controls are shown.
First, I need to clear my parent panel(s) of all dynamically added items before adding again. But, to the point of the question, calling ReportViewerInstance.RefreshReport() should cause the dynamically added controls to become visible before the initial rendering of the report. I am about to try this scenario. I am not certain yet how I am going to call the instance of the report viewer, but at minimum, I should be able to pass a reference to the instance as a report parameter, or similar.
RefreshReport() call found in this Telerik help post:
I will update with my results after trying the above.
UPDATE: RefreshReport did NOT work for me - it cancelled the processing and resulted in no report. However, I did solve my issue. And, it should solve the OP's issue as well.
Eric's code shows trying to create and show the dynamically added controls in an ItemDataBinding event. I was doing the same, and also tried ItemDataBound. Both of these events occur when processing is in action, and a help topic regarding a dynamically added table control tipped me off. The Telerik expert recommended not altering the report items during processing to avoid unpredictable behavior. Following that, I moved my code to create controls into a method (not an event) and call it from my Report.NeedDataSource event, after instantiating all needed data objects, and before setting the report datasource as one of my object collections. This works great!
I hope this helps someone else!

C# dynamic label blank

I created a very basic console app that executes some code behind the scenes. While it's doing this, it generates a custom message box (it's technically a Windows Form) that just displays one label telling the user to please wait. The issue is that the label NEVER is displayed (it's just a big white box where the label should be). I tried creating a dynamic label and putting it there, but this too does not work.
The form is shown in the following manner:
public void DoSomething()
{
MyForm form = new MyForm();
form.Show();
try {
// Execute other logic
} finally { form.Close(); }
}
I'm guessing it has something to do with calling Show(), but I'm not positive. I put in logging and see that it's going through the constructor, generating the dynamic label (which is added to the form via Controls.Add(myLabel)), but it still does not show any label.
A Form requires the message pump to be started in order to display correctly. This requires calling Application.Run. Unfortunately, this will block the current thread until the "application" is complete, so won't be able to just "drop in" to your code.
That being said, if you're developing an application which requires windows, you should consider making it a true windows application instead of a console application. You could just hide the main form, if required, and that will allow code like yours above to work properly.

How to make a touchable notice top bar in windows phone?

How to make a touchable notice top bar in windows phone ?
I am new to C# and windows phone world.So may be my question has a simple
way to solve,but I google a lot ,and didn't work out.
here is my purpose: I have a timer running throughout my app,it request a
service for notice info every one hour, and show a "notice bar" on the top of
screen.
it is easy to get the information ,but when I want to show them to the Page,
here is my problem:
1.
I used system tray to show my info.
It works,but then I found there is no touch or click event for Progress
Indication bar.
I even add an event to Touch.FrameReported in App.xaml.cs , but still ,
when i touch the system tray area, the event doesn't fire.
2.
Then I want to use a Dynamic way to achieve it: add a text block to the
current page
I got the current page handler ,but case I only know the current page
handler's type is PhoneApplicationPage, I can't get my Root UI element
(all my page has a root element named "LayoutRoot")
And when I try to use reflect method to get the "LayoutRoot" property,
the return value is null.
The code looks like this :
Type type = PhoneApplicationPageHandler.getType()<
//I checked,the type is my page's type
type.getProperty("LayoutRoot") or type.getField("LayoutRoot")
//they all return null
BTW: LayoutRoot is a grid, and it is described in my page's .xmal file.
Now My option is to make all my page inherit a defalut page ,in this page ,I will
implement a method to fulfill my second way to simulate a "touchable top bar".
but I think this coding is ugly .
So, can anyone tell me :
1.how to add touch event to a SystemTray
or
2.how to get a handler of an ui element which is described in xaml, while I only have a PhoneApplicationPage type handler of that page.
You may use
1) a toast prompt described here http://windowsphonegeek.com/articles/WP7-Toast-Prompt-in-depth
2)or shell toast described here http://www.c-sharpcorner.com/UploadFile/ae35ca/working-with-toast-notification-in%C2%A0windows-phone-7/ according to what suits your requirement the best. 3)You may also create a custom control which you may place on the top on your mainPage and handle its tap event accordingly.

Categories

Resources