|
Have a look at the WindowsIdentity.AuthenticationType[^] property. If the user is logged in using a Microsoft account, it should return CloudAP .
var identity = System.Security.Principal.WindowsIdentity.GetCurrent();
bool isMicrosoftAccount = identity.AuthenticationType == "CloudAP";
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Many thanks for the quick response !
it works like a charm !!
|
|
|
|
|
Hi,
I have the following code:
class Program
{
static void Main(string[] args)
{
ProductCounterWatcher w = new ProductCounterWatcher();
ICounterProcessor p = new PrdStandStillDetector();
w.OnCounterChanged += p.CounterChanged;
w.Detect();
w.OnCounterChanged -= p.CounterChanged;
}
}
public class ProductCounter
{
public int Value { get; set; }
public DateTime Timestamp { get; set; }
public override string ToString()
{
return string.Format("[ProductCounter:{0},{1}]", Timestamp, Value);
}
}
public interface ICounterProcessor
{
void CounterChanged(object source, CounterChangedEventArgs e);
}
public delegate void CounterChangedHandler(object source, CounterChangedEventArgs e);
public class CounterChangedEventArgs : EventArgs
{
public ProductCounter Counter { get; set; }
public CounterChangedEventArgs(ProductCounter counter)
{
this.Counter = counter;
}
}
public class PrdStandStillDetector : ICounterProcessor
{
public void CounterChanged(object source, CounterChangedEventArgs e)
{
}
}
public class ProductCounterWatcher
{
public CounterChangedHandler OnCounterChanged;
public void Detect()
{
if (OnCounterChanged != null) OnCounterChanged(this, new CounterChangedEventArgs(new ProductCounter() { Timestamp = DateTime.Now, Value = 1 }));
}
}
I have to define the procedure signature twice (see <<<--- mark). is there a way to avoid this and thus only define the signature once?
Thanks.
|
|
|
|
|
So you're not really defining it twice; you're defining it once and then defining a delegate with a matching signature in the interface,
Here's what I think you're looking for:
public delegate void CounterChangedHandler(object source, CounterChangedEventArgs e);
public interface ICounterProcessor
{
CounterChangedHandler CounterChanged { get; }
}
When you have pre-defined delegates like this, you can use them in the same way that you would Action or Func.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
modified 22-Jan-18 7:56am.
|
|
|
|
|
Thank you for the reply. It is not what I mean; In your solution the ICounterprocessor can raise the event, but it's meant to react on the event, like an observer. Maibe I better forget the whole event stuff, and change to Observer like structure?
|
|
|
|
|
No sir, I'm afraid that's not correct. That would be:
public interface ICounterProcessor
{
event CounterChangedHandler CounterChanged;
}
But I didn't format it as an accessor, so I'll take bads on that (I've been playing using abstracts too much lately rather than interfaces).
So I modified the code snippet in the last to make it a property accessor. It will work, and is much less complicated than an Observer pattern. Try it
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
How about using the built-in EventHandler<TEventArgs>[^] delegate?
You should also mark the event with the event keyword, and drop the "On" prefix to follow the .NET naming standards.
public class ProductCounterWatcher
{
public event EventHandler<CounterChangedEventArgs> CounterChanged;
public void Detect()
{
EventHandler<CounterChangedEventArgs> handler = CounterChanged;
if (handler != null) handler(this, new CounterChangedEventArgs(new ProductCounter() { Timestamp = DateTime.Now, Value = 1 }));
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Oke, that makes sense. Thank you.
|
|
|
|
|
Hello, when I press the X in the top right hand corner of the application, I get a messagebox. The messagebox ask me a Yes/No question. If I press YES, all is good and the application closes. When I press NO, I can continue to use the application. Now the problem. If I press NO, then I can never press the X in the top right hand corner. It's as if the NO answer disables the ability to ever close the application again. How can I say NO and be able to press the X again when I want to close the application later?
Code:
private void DXWindow_Closing(object sender, CancelEventArgs e)
{
var result =
MessageBox.Show(
Properties.Resources.MainWindowMsgBox3 + Environment.NewLine +
Properties.Resources.MainWindowMsgBox4 + Environment.NewLine + Environment.NewLine +
Properties.Resources.MainWindowMsgBox5,
Properties.Resources.MainWindowMsgBox6, MessageBoxButton.YesNo, MessageBoxImage.Question,
MessageBoxResult.No);
Log.Info("User engaged Application Closure Event");
switch (result)
{
case MessageBoxResult.Yes:
Log.Info("Main Window Closed");
OnClosed(e);
Application.Current.Shutdown();
break;
case MessageBoxResult.No:
e.Cancel = true;
break;
}
}
|
|
|
|
|
First, I think you should call the base OnClosing method, not the OnClosed as you do. Second, you should call this base handler in both cases, as it will take care with proper action, whether or not event has been cancelled:
var result =
MessageBox.Show(
Properties.Resources.MainWindowMsgBox3 + Environment.NewLine +
Properties.Resources.MainWindowMsgBox4 + Environment.NewLine + Environment.NewLine +
Properties.Resources.MainWindowMsgBox5,
Properties.Resources.MainWindowMsgBox6, MessageBoxButton.YesNo, MessageBoxImage.Question,
MessageBoxResult.No);
Log.Info("User engaged Application Closure Event");
switch (result)
{
case MessageBoxResult.Yes:
Log.Info("Main Window Closing");
break;
case MessageBoxResult.No:
e.Cancel = true;
break;
}
base.OnClosing(e);
The whole point of setting the Cancel property is to let the base handler know which action to take (close or cancel).
Hope this helps.
"I'm neither for nor against, on the contrary." John Middle
|
|
|
|
|
That's not working either. All it does is ask over and over again if I want to close the application. Did I mention this was inside a Closing event on the window?
private void DXWindow_Closing(object sender, CancelEventArgs e)
|
|
|
|
|
Oups, I misread; yes you're right, you did not override the base handler, so there is no point calling it. What happens if you comment off the base.OnClosing(e); line?
"I'm neither for nor against, on the contrary." John Middle
|
|
|
|
|
Commenting out the line pops the message when the X is clicked. If I say YES, the app closes. If I say NO, I return to the application; however, the X is dead. I can no longer close the application.
|
|
|
|
|
I want to apologize for not catching this the first time. I reviewed the issue with DevExpress and they reported that the Closing Event is only being raised once and this defect will be fixed in the next release. Article. thanks for your help!
|
|
|
|
|
You're welcome. Thanks for the update. I don't feel like I was of great help, though.
"I'm neither for nor against, on the contrary." John Middle
|
|
|
|
|
What I mean by...
Moveable elements: index cards, scrabble tiles, etc.
move: 'grab' and drag with LMB to another part of the window
I'm new to C# and WFC, etc. but have years of experience in PHP, C and other languages.
What I'm looking to know is:
- which element(s) (if element is the right word; checkbox? text entry field? what-have-you?) to use to create a scrabble tile or index card (whatever; the moveable object/thing)
- how movement is handled
Either a general sort-of pseudo code explanation or actual code is fine.
I don't know the terminology used in WFC (if WFC is even the right acronym) so maybe this question doesn't even make sense.
|
|
|
|
|
Member 13588277 wrote: if WFC is even the right acronym For what?
And if you want to know the answers to he other questions then take a look in the Articles section[^] where you will find lots of useful information.
|
|
|
|
|
For game "pieces" I'd use either a Panel for rectangular pieces, or a UserControl for custom shaped pieces.
Search CodeProject for articles on drag and drop, and/or creating custom shaped Controls.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
The elements you refer to are from WinForms, and that's not a great engine to build games with. Ever heard of Rimworld? Might not have, as it is still in beta, but it is available on Steam.
Engine Used?[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Upvote for a Rimworld reference.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Thanks for all the replies, guys.
Eddy Vluggen wrote: The elements you refer to are from WinForms, and that's not a great engine to build games with
Eddy: What do you use instead of WinForms? And which specific element (or whatever it's called) would you use for (for instance) an index card that can be dragged around and dropped somewhere else within a window?
|
|
|
|
|
Unity
It has a learning curve, but not a terrible one.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Member 13588277 wrote: And which specific element (or whatever it's called) would you use for (for instance) an index card that can be dragged around and dropped somewhere else within a window? It's hard to say it, I hate to say it, but probably WinForms. It has got built-in support for drag and drop, and there's an article on CodeProject showing how to use any bitmap in that drag-and-drop operation.
If you are into creating games, I'd strongly suggest to look at Unity. If you're looking for beta-testers, I'm here
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You're probably thinking of WPF (Windows Presentation Foundation); and not WFC.
I would consider the WPF "Canvas" control as a starting point for an "absolute positioning" project:
How to: Create and Use a Canvas | Microsoft Docs
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Is this WPF thing out of beta yet?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|