i am a Student and just startet programming and try out ILNumerics.
Here is my question:
How can i refresh or replot a IlPanal after changing colormap or userdata?
I want to refresh the Surfacegraph by clicking on a button. I guess the answer is very easy, but i tried a lot the last two days... i'm a noob ;)
For example:
private void ilPanel_3D_Load(object sender, EventArgs e)
{
var scene = new ILScene();
var pc = scene.Add(new ILPlotCube(twoDMode: false));
var sf = pc.Add(new ILSurface(Z));
ilPanel_3D.Scene = scene;
}
private void button1_Click(object sender, EventArgs e)
{
// dont know what to put in here...
}
thanks
For such interactive actions you will have to access the 'synchronized copy' which every driver internally maintains of the global scene. Since a scene may get displayed by many drivers at the same time, this internal copy only reflects all changes due to user interaction / modifications.
private void button1_Click(object sender, EventArgs e) {
ilPanel_3D.GetCurrentScene().First<ILSurface>().Colormap = Colormaps.Summer;
ilPanel_3D.Refresh();
}
PS: no need to wait for two days the next time ... ! ;)
#Edit2: Actually, the update works just fine on the global scene also. But in order to broadcast the change to the ilPanel1 driver, you will have to add a call to Configure() at the end of your modifications. Configure can be called once for all changed nodes on one of their common parent nodes. So, you might simply call Configure() on the scene:
private void button1_Click(object sender, EventArgs e) {
ilPanel_3D.Scene.First<ILSurface>().Colormap = Colormaps.Summer;
ilPanel_3D.Scene.Configure();
ilPanel_3D.Refresh();
}
Related
I need to refresh webView control when the ui size changed. I used SizeChanged event in some controls like Border, WebView, etc SizeChanged event. But I got this system.invalidoperationexception 'a method was called at an unexpected time error. I got this error at the beginning of running the application. The way I used:
<WebView x:Name="webView" SizeChanged="OnSizeChanged" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<WebView.Source>
...
</WebView.Source>
</WebView>
private void OnSizeChanged(object sender, EventArgs e)
{
webView.Reload();
}
Probably I used it in wrong way, or could it be a bug?
I solved the problem when I used Reload method in try-catch:
private void OnSizeChanged(object sender, EventArgs e)
{
try
{
webView.Reload();
}
catch(Exception ex)
{
}
}
I have a Xamarin.Forms app and I am using FreshMvvm framework.
If I do this from ViewIsAppearing method of FirstPageModel:
CoreMethods.PushPageModel<SecondPageModel>();
I go the "SecondPageModel". Then, when I am in the "SecondPageModel" if I do:
CoreMethods.PopPageModel();
or press hard back button, or press title bar back button not works in Android (anything happens). I am using FreshMasterDetailNavigationContainer.
In iOS it works OK, I get back to FirstPageModel.
This is because ViewIsAppearing will always be called when the page starts displaying on the screen. When you pop the second page then go to the first page, the first page's ViewIsAppearing will fire again. It caused a dead cycle and prohibited your app from returning to the first page.
Add a property to avoid that:
bool isInitialized;
public FirstPageModel()
{
// ...
isInitialized = true;
}
protected async override void ViewIsAppearing(object sender, EventArgs e)
{
base.ViewIsAppearing(sender, e);
if (isInitialized)
{
await Task.Delay(100);
await CoreMethods.PushPageModel<SecondPageModel>();
isInitialized = false;
}
}
iOS may optimize this process, but I still recommend you to add this judgment statement.
Update:
Call it when your app has reached the main thread.
protected override void ViewIsAppearing(object sender, EventArgs e)
{
base.ViewIsAppearing(sender, e);
if (isInitialized)
{
Device.BeginInvokeOnMainThread(() =>
{
CoreMethods.PushPageModel<SecondPageModel>();
isInitialized = false;
});
}
}
I'm trying to write a Word add-in that uses a CustomTaskPane. I'm able to create the CustomTaskPane and synchronize it between open documents, and I get no errors as long as I use the Word menu when I add a new or open an existing document. However, if I add a new document through a ribbon button that calls Globals.ThisAddIn.Application.Documents.Add(), I start getting COMExceptions when I close documents.
The issue appears to be when I add a new document using the button click event in CtpMainRibbon.cs instead of through the Word menu, the Globals.ThisAddIn.Application.ActiveWindow property is invalid after closing an open document. On the get for the CurrentCustomTaskPane property, ActiveWindow returns a System.Runtime.InteropServices.COMException: 'This command is not available because no document is open.' at Microsoft.Office.Interop.Word.ApplicationClass.get_ActiveWindow(). I've searched for the error but most of the issues are when people try to use the Word Interop on a server or an ASP.net page, but I'm getting this on my development machine. Also, if I use the Document.Add() method, the Show button's check status doesn't display correctly (if I have a CustomTaskPane open in one document, then click the New Document button on the ribbon, the new document's Show button is checked even though the task pane isn't visible. If I switch to a different window then switch back to the new document, the button's checked status updates to unchecked.
I've tried looping through Globals.ThisAddIn.CustomTaskPanes to see if there's a mismatch between the ctp.Window.Hwnd properties, but as far as I can tell, each ctp.Window has its own unique Hwnd. I get the message even when there are other documents and windows open.
Here's the 2 pertinent code files. I use CurrentCustomTaskPane so the ribbon button can sync up with the Visible property of the task pane.
ThisAddIn.cs:
private const string TaskPaneTitle = "Main Custom Task Panel";
public static CustomTaskPane CurrentCustomTaskPane
{
get
{
return Globals.ThisAddIn.CustomTaskPanes
.FirstOrDefault(ctp => !ctp.Control.IsDisposed &&
Globals.ThisAddIn.Application.ActiveWindow != null &&
ReferenceEquals(ctp.Window, Globals.ThisAddIn.Application.ActiveWindow) &&
ctp.Title == TaskPaneTitle);
}
}
private void InternalStartup()
{
Startup += ThisAddIn_Startup;
Shutdown += ThisAddIn_Shutdown;
}
private void ThisAddIn_Startup(object sender, EventArgs e)
{
if (Application.Documents.Count > 0)
AddNewTaskPane(Application.ActiveDocument);
Word.ApplicationEvents4_Event event4 = Application;
event4.NewDocument += OnNewDocument;
event4.DocumentOpen += OnDocumentOpen;
event4.WindowActivate += ApplicationOnWindowActivate;
}
private static void ThisAddIn_Shutdown(object sender, EventArgs e) { }
private void OnNewDocument(Word.Document doc) => AddNewTaskPane(doc);
private void OnDocumentOpen(Word.Document doc) => AddNewTaskPane(doc);
private void ApplicationOnWindowActivate(Word.Document doc, Word.Window wn) => SetRibbonButtonToggle();
private void AddNewTaskPane(Word._Document doc)
{
RemoveOrphanedTaskPanes();
CustomTaskPane newPane = CustomTaskPanes.Add(new MainCustomTaskPanel(), TaskPaneTitle, doc.ActiveWindow);
newPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionLeft;
newPane.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
newPane.Width = 700;
newPane.VisibleChanged += TaskPaneOnVisibleChanged;
}
private void TaskPaneOnVisibleChanged(object sender, EventArgs e) => SetRibbonButtonToggle();
private void SetRibbonButtonToggle()
{
if (CurrentCustomTaskPane != null)
Globals.Ribbons.CtpWordRibbon.RbnButtonShowTaskPane.Checked = CurrentCustomTaskPane.Visible;
}
private void RemoveOrphanedTaskPanes()
{
foreach (CustomTaskPane ctp in CustomTaskPanes)
{
if (ctp.Window == null || ctp.Control.IsDisposed)
CustomTaskPanes.Remove(ctp);
}
}
CtpWordRibbon.cs:
private void RbnButtonShowCtp_Click(object sender, RibbonControlEventArgs e)
{
if (ThisAddIn.CurrentCustomTaskPane != null)
ThisAddIn.CurrentCustomTaskPane.Visible = ((RibbonToggleButton)sender).Checked;
}
private void RbnButtonCreateNewDocument_Click(object sender, RibbonControlEventArgs e)
{
Globals.ThisAddIn.Application.Documents.Add();
}
There's obviously a difference between how Word handles adding a new document through the Word menu and adding it with the Application.Documents.Add() method. How can I check to see if the ActiveDocument property is going to throw an COMException before I actually access it? Or is there an better way to create a new document through the ribbon, or handle the OnNewDocument event so I'm not getting these errors?
I have below code written inside C# Form application where I am trying to get x,y and z co-ordinates from Leap Motion device.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//controller.EventContext = WindowsFormsSynchronizationContext.Current;
button1.Click += new EventHandler(button1_Click);
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
// Initialize the Controller object which connects to the Leap motion service
// and captures the hand tracking data
Controller controller = new Controller();
//Get the most recent tracking data using the Frame object
Frame frame = controller.Frame();
for (int h = 0; h < frame.Hands.Count; h++)
{
// Initialize the Hand in the given frame
Hand leapHand = frame.Hands[h];
// Get the "Pointer" finger of current hand which refers to where a person is pointing
Finger leapFinger = leapHand.Fingers[1];
// Prepare a vector which will store the co-ordinate values of the tip of the pointer
Vector currentPosition = leapFinger.StabilizedTipPosition;
textBox1.Text = Convert.ToString(currentPosition.x);
textBox2.Text = Convert.ToString(currentPosition.y);
textBox3.Text = Convert.ToString(currentPosition.z);
}
}
}
However, I need to explicitly click the button1 to display.
Any idea what's wrong ?
Here is an overly simple example of one way to do it. I'm not saying it's the best way, but you should be able to modify this sample code with your code.
In this example, there is a simple "HelloWorld" method that is called when the form is initialized as well as whenever you press the button. Let me know if this gets you close to what you're after.
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Click += new EventHandler(button1_Click);
HelloWorldTest();
}
private void button1_Click(object sender, EventArgs e)
{
HelloWorldTest();
}
private void HelloWorldTest()
{
MessageBox.Show("Hello World!");
}
}
}
For what it's worth, I didn't use your code because I don't have the Leap libraries installed and if there was a typo, I wouldn't be much help to resolve it. Nonetheless, hopefully it gets you going down the right path.
This is kind of a stupid question... I'm trying to drag and drop a picturebox onto a panel. I followed some exemples, but it doesn't work. The DragDrop event of the panel is never raised. I searched thi site for a solution andfound two topics over a year old, but their solutions did not work. I created a new project, with only this code :
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
pictureBox1.MouseDown += new MouseEventHandler(pictureBox1_MouseDown);
panel1.DragDrop +=new DragEventHandler(panel1_DragDrop);
panel1.DragOver +=new DragEventHandler(panel1_DragOver);
}
private void panel1_DragOver(object sender, DragEventArgs e)
{
Console.WriteLine("DragOver");
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
Console.WriteLine("DragDrop");
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
Console.WriteLine("Mouse");
pictureBox1.DoDragDrop(pictureBox1.Text, DragDropEffects.All);
}
}
I also set the AllowDrop of the panel and the form to true. DragOver and MouseDown are raised. Also, when I drag the picturebox, the cursor become a barred circled, like it was an operation that wasn't allowed. Is there a way that the cursor becomes the image in the picture box? I don't want the picturebox to move, only to add an item to the panel.
The problem is easy to solve.
You must just set in DragEnter appropriate Effect:
private void Form1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
After that DragDrop event is fired correctly.
Richard, the problem is that drag and drop is not as simple operation as you have coded here. Here you haven't started the drag movement which should start with code and you can read more about it here... http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dodragdrop(v=VS.90).aspx
If you just want to move the PictureBox... dragging picturebox inside winform on runtime
And finally Drag and Drop between Instances of the same Windows Forms Application
Hope this helps.