Mouse event with RadPageView - c#

I have a problem with RadPageView on catch mouse event when I'm building an app using Telerik UI for WinForms.
I just want to catch mouseover event of some page in a page view. In this case, I want to show the content while a page header is under pointer.
For example, I have a page view named "Page" and it has 2 pages are "A" and "B". I want to show these page's content when the pointer point to them.
Please give me a solutions for this case.
Thanks,
Sorry for my bad English.

Here you are:
private void RadPageView1_MouseMove(object sender, MouseEventArgs e)
{
RadPageViewItem hoveredItem = radPageView1.ElementTree.GetElementAtPoint(e.Location) as RadPageViewItem;
if (hoveredItem != null)
{
radPageView1.SelectedPage = hoveredItem.Page;
}
}

For me, e.location was not behaving properly in some corner cases (multiple pages were getting hovered if we moved cursor in a certain way).
I used below logic (use of isMouseOver property of each item) and it works perfectly:
private void RadPageView1_MouseMove(object sender, MouseEventArgs e) {
foreach (RadPageViewPage pageView in radPageView1.Pages) {
if (!pageView.Item.IsMouseOver) {
//your logic for hovered pages
} else {
//your logic (if any) for non-hovered pages
}
}
}

Related

Navigating to specific ContentFrame when refreshing NavigationView

I have an app which uses a NavigationView as a UI-control.
Now I have a SettingsPage where I can change the language of my UI between german and english.
I change the language with this code:
public static void German()
{
Log.Logger.Information("Language = German")
ApplicationLanguages.PrimaryLanguageOverride = "de-DE";
DataCollection.Current.LanguageChangedEvent.LanguageChanged();
}
The last line invokes an EventHandler which in turn invokes the following event on the MainPage.xaml.cs where the NavigationView is located.
public void ChangedLanguage(object source, EventHandlerBase e)
{
if (e.GetStatus())
{
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Reset();
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForViewIndependentUse().Reset();
Frame.Navigate(this.GetType());
ContentFrame.Navigate(typeof(SettingsPage));
}
}
As it's possible to see I just want to return the user to the SettingsPage after changing the language.
But I always return back to the initial HomePage that I use when starting the app.
The code I use for the NavigationView is derived from the official NavigationView sample provided by Microsoft.
Is there any possible way to do this? The only possible thing I can imagine is to set a flag after the first page loading and then always check if that flag is set. But then I have the problem that I still could only land at the SettingsPage because I would have to make it the else destination for the flag-check.
Would really appreciate a more dynamic way if thats even possible :/
Greeting,
Daniel
The NavigationView sample just is a simple code sample for your reference. You need to make some changes by your requirements.
I just want to return the user to the SettingsPage after changing the language. But I always return back to the initial HomePage that I use when starting the app.
I've used the code on the document to make a code sample for testing. There're two places will cause your question.
First, in the NavView_Loaded event handler, it will always sets the home page as the selected item. But when you change the language, you re-navigate to 'MainPage' and make 'ContentFrame' navigate to 'SettingsPage'. At this time, the On_Navigated event handler will be first called. Then, the NavView_Loaded event handler will be called. That's the reason why your app always will return to home page.
Second, event if the NavigationView's SelectedItem has been set. But the NavigationView's ItemInvoked event will not be fired. So, what you see actually is not home page, it's a blank Frame control. You could use SelectionChanged event instead of ItemInvoked event. The SelectionChanged event will be fired when you set a new value for the NavigationView's SelectedItem. See the following sample:
private void NavView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
if (args.IsSettingsSelected)
{
ContentFrame.Navigate(typeof(SettingsPage));
}
else
{
NavView_Navigate(args.SelectedItem as NavigationViewItem);
}
}
Then, let's back to your original question:
I can imagine is to set a flag after the first page loading and then always check if that flag is set. But then I have the problem that I still could only land at the SettingsPage because I would have to make it the else destination for the flag-check.
In my opinion, the flag will not affect you doing other things. You completely could define several flags. Please see my following code snippet for reference:
public static void German()
{
Log.Logger.Information("Language = German")
ApplicationLanguages.PrimaryLanguageOverride = "de-DE";
ApplicationData.Current.LocalSettings.Values["IsSwitchingLanguage"] = true;
DataCollection.Current.LanguageChangedEvent.LanguageChanged();
}
In your MainPage.xaml.cs:
public void ChangedLanguage(object source, EventHandlerBase e)
{
if (e.GetStatus())
{
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Reset();
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForViewIndependentUse().Reset();
Frame.Navigate(this.GetType());
}
}
In NavView_Loaded event handler, I made some changes:
private void NavView_Loaded(object sender, RoutedEventArgs e)
{
......
foreach (NavigationViewItemBase item in NavView.MenuItems)
{
var IsSwitchingLanguage = ApplicationData.Current.LocalSettings.Values["IsSwitchingLanguage"];
if (IsSwitchingLanguage != null)
{
if ((bool)IsSwitchingLanguage)
{
NavView.SelectedItem = NavView.SettingsItem as NavigationViewItem;
ApplicationData.Current.LocalSettings.Values["IsSwitchingLanguage"] = false;
break;
}
}
if (item is NavigationViewItem && item.Tag.ToString() == "home")
{
NavView.SelectedItem = item;
break;
}
}
......
}

Detect the bottom of a WebBrowser Page in Windows Phone 8

I have a xaml page in which I have used a webbrowser control.I need to scroll down to the web page and once the bottom is reached,I have to enable a button.
Thanks in advance!
There's two part to this. The first is to detect, in Javascript, the moment when the browser reaches the bottom of the page. The second is to forward the event to the C# code.
Say you ask your WebBrowser control to navigate to a given page. First, in the C# code, subscribe to the Navigated event to inject the proper Javascript code:
private void WebBrowser_Navigated(object sender, NavigationEventArgs e)
{
const string Script = #"window.onscroll = function() {
if ((window.innerHeight + document.documentElement.scrollTop) >= document.body.offsetHeight) {
window.external.notify('bottom');
}
};";
this.WebBrowser.InvokeScript("eval", Script);
}
This Javascript code uses the window.external.notify method to notify the C# code. To receive the notification, you need to subscribe to the ScriptNotify event of the WebBrowser:
private void WebBrowser_ScriptNotify(object sender, NotifyEventArgs e)
{
if (e.Value == "bottom")
{
// Reached the bottom of the page
}
}

Winforms ListView MouseUp event firing more than once

In my .NET 4,5 Winforms application, the ListView control's MouseUp event is firing multiple times when I open a file from that event as follows:
private void ListView1_MouseUp(object sender, MouseEventArgs e)
{
ListViewHitTestInfo hit = ListView1.HitTest(e.Location);
if (hit.SubItem != null && hit.SubItem == hit.Item.SubItems[1])
{
System.Diagnostics.Process.Start(#"C:\Folder1\Test.pdf");
MessageBox.Show("A test");
}
}
Note: When clicking on the SubItem1 of the listview, the file opens but the message box appears at least twice. But, when I comment out the line that opens the file the message box appears only once (as it should). I do need to open the file whose name is clicked by the user in the listview. How can I achieve this without the MoueUp event firing multiple times?
Please also note that the MouseClick event for listview does not always work as also stated here. So, I have to use MouseUp event.
EDIT: I should mention the ListView is in Details mode.
Avoid HitTest() and use ListView's native function GetItemAt(). An example from MSDN looks like this:
private void ListView1_MouseDown(object sender, MouseEventArgs e)
{
ListViewItem selection = ListView1.GetItemAt(e.X, e.Y);
// If the user selects an item in the ListView, display
// the image in the PictureBox.
if (selection != null)
{
PictureBox1.Image = System.Drawing.Image.FromFile(
selection.SubItems[1].Text);
}
}

Choosing an MSChart-Extension tool from button click

I am using MSChart-Extensions and I would like the option to choose the Zoom, Pan and Select tools from a button, as well as from the ContextMenuStrip. I feel like the easiest way is to simulate a click from the ContextMenuStrip.Items collection
Here is what I've got. In my form I have this
private void zoomButton_Click(object sender, EventArgs e)
{
this.chart.ChangeTool("Zoom");
}
And in MSChartExtensions.cs I have this
public static void ChangeTool(this Chart sender, string option)
{
Chart chart = sender;
foreach(ToolStripItem item in chart.ContextMenuStrip.Items)
{
if (item.Text == option)
{
item.PerformClick();
break;
}
}
}
This successfully chooses the tool from the collection. However, I am getting a System.ArgumentNullException in the SetChartControlState method. I have stepped through the code and I see that when the application enters ChartContext_ItemClicked, the sender's source control is null. I've dug through MSDN, and found this
A Control that represents the control that is displaying the shortcut menu. If no control has displayed the shortcut menu, the property returns a null reference (Nothing in Visual Basic).
So I assume that because no right-click menu (ContextMenuStrip) is shown, the source control is null. Is there a way around this? How can I get this working? Thanks for the help
I figured it out. Change the ChangeTools() method to this
// In MSChartExtensions.cs
public static void ChangeTool(this Chart sender, string option)
{
if (option == "Zoom")
SetChartControlState(sender, MSChartExtensionToolState.Zoom);
else if (option == "Select")
SetChartControlState(sender, MSChartExtensionToolState.Select);
else if (option == "Pan")
SetChartControlState(sender, MSChartExtensionToolState.Pan);
else if (option == "Zoom Out")
{
Chart ptrChart = sender;
WindowMessagesNativeMethods.SuspendDrawing(ptrChart);
ptrChart.ChartAreas[0].AxisX.ScaleView.ZoomReset();
ptrChart.ChartAreas[0].AxisY.ScaleView.ZoomReset();
ptrChart.ChartAreas[0].AxisY2.ScaleView.ZoomReset();
WindowMessagesNativeMethods.ResumeDrawing(ptrChart);
}
}
And then call this method like how I did in the question
// In the form
private void zoomButton_Click(object sender, EventArgs e)
{
this.chart.ChangeTool("Zoom"); // As an example
}
If anyone has a better way of doing this, feel free to let me know

How to hide the tool tips

I am having a treeview with some nodes. I am also having a panel. I have taken some usercontrol forms and i will load those usercontrols when corresponding node is selected from the child hood. Now what i need is have some validations like if i left the text box empty i will have some tooltips displayed to the user. Suppose if i click on first node i will have a user control loaded. With out giving any values if i hit ok i will have some tool tips as follows
Now if i select the second node from the tree still the tooltips getting displayed i would like to hide those
Any Help please
my code for rasing error tooltips is as shown below
public class TestClass
{
public void RequiredText(TextBox txtTemp, ToolTip newtoolTip)
{
if (txtTemp.Text != string.Empty)
{
txtTemp.BackColor = System.Drawing.Color.White;
newtoolTip.Hide(txtTemp);
}
else
{
txtTemp.BackColor = System.Drawing.Color.Tomato;
newtoolTip.Show("Required", txtTemp);
}
}
}
But this was done in the use control form.
I haven't yet mastered the art of reverse-engineering code from a screenshot. I'm guessing that you don't dispose the previous user control when you select a new one. Allowing the tool tip to stay visible. Use code like this:
private UserControl currentView;
public void SelectView(UserControl view) {
if (currentView == view) return;
if (currentView != null) currentView.Dispose();
if (view != null) this.Controls.Add(view);
currentView = view;
}
And call SelectView() from the TreeView's AfterSelect event handler.
Have you tried the Hide method?
http://dotnetperls.com/tooltip
Got the answer just written Usrcntrl_Leave event for every user control as
private void usrcntrlPPD_Leave(object sender, EventArgs e)
{
this.Dispose();
}
This solved my problem :)
private void timer1(object sender, EventArgs e)
{
count++;
if (count == 2)
{
toolTMensaje.SetToolTip(textBox1,"");
toolTMensaje.Hide(textBox1);
count = 0;
timer1.Stop();
}
}

Categories