|
Member 13014278 wrote: So, if my code do what you said, what miss in my code? The approach is wrong. Overlaying the desktop with a transparent form means you'll eat some of the events.
Member 13014278 wrote: I didn't understood. Can you help me? I tried, but it didn't work.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi Eddy.
Thanks.
Yes I understood what you said. And have the topics that you said:
1. Add image to a small transparent form
2. Get the coordinates of the systems cursor
3. Change the location of your form to somewhere near those locations
Right?
But I think that the 1. I already did, you can check?
Can you help me in next steps?
|
|
|
|
|
Member 13014278 wrote: But I think that the 1. I already did, you can check? It should not be maximized.
Member 13014278 wrote: 2. Get the coordinates of the systems cursor Something like pinvoke.net: getcursorpos (user32)[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi Eddy.
Thanks. It was very useful the first tip.
The second I think that I already have. Check please. Is not the same thing?
<pre> [DllImport("user32.dll")]
public static extern bool GetCursorPos(out POINT lpPoint);
public static Point GetCursorPosition()
{
POINT lpPoint;
GetCursorPos(out lpPoint);
return lpPoint;
}
|
|
|
|
|
Yes, that's the one; you'll need this[^] - if you read that, you'll notice that the call could fail. To use my computer as an example, the "current desktop" is not always the normal windows desktop.
Next thing to notice is that the call does not return a C# location on a Screen object, but screen-coordinates. You may need to convert or translate that to get a C#-point. Once you have that, you can set the top and left-properties of your small form to that location.
The form would also need to be the "topmost" form, otherwise it will sometimes dissapear behind other windows. The problem with "topmost" is that there might be multiple applications wanting to claim the same thing.
That would be one possible solution. Another might be to replace the entire cursor. It should be possible to get the current settings of the user and find out the current cursor, to load that as an image, add your image to that, and replace the entire cursor with the newly merged image. That would create conflicts in applications where the cursor changes (like to the hourglass, or on mouseovers) though.
I'd consider both a 'hackish' solution, and I doubt MS supports such a scenario. You may want to use the MSDN forums to check if there is a supported way to achieve the same (which will add complexity, ofc).
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi Eddy. Thanks.
The link that you sent is in C++. I want in C#. The idea that replace entire cursor in system I don't like. I want add an image that moves the cursor just this. Do you know how I can do this?
|
|
|
|
|
What you want to achieve is not available as a pure C# solution. The WinAPI documentation is for C++ developers, or people who interop from another language as C#.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
I am trying to understand how to write a multiplatform library with either .NET core / standart.
(remark before I was using PCL but it's fidly with target framework, I was hoping it wil be easier with .NET Core/standart)
here is my simple library class
namespace ClassLibrary1
{
public class Class1
{
public static void DoFoo()
{
Console.WriteLine("hello");
}
}
}
Now I try to use it in a console app (targeting .NET 4.6.2)
In .NET Standard library, it compiles but I get the following runtime error:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Console, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
In a .NET Core library, I got compiler error:
3>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.Common.targets(73,5): error : Project 'H:\Temp\ConsoleApp3\ClassLibrary2\ClassLibrary2.csproj' targets '.NETCoreApp,Version=v1.1'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.6.2'.
I am at loss how to go any further... :'(
Can someone enlightnen me on what's going on
(didn't find how to add System.Console reference DLL to my .NET standard library)
[EDIT] Solved it!
I had to use Nuget to add System.Console to my console app and then it worked!
Interesting...
I have to investigate how this ll work and test this .NET Standard library on Android!
|
|
|
|
|
I'm trying to plot the data read from a serial port using zedgraph. I'm still learing to code so I couldn't deduce why the plot does not work. Please have a look at the code and advice.
To open and read from a serial port, I use a combox and a couple of buttons (and then later I try to save it to a text file).
The plot does not update! I can't quite guess why. Please tell me if there's mistakes in my approach or the code.
namespace WindowsApplication2
{
public partial class Form1 : Form
{
string t;
SerialPort sp;
Thread m_thread;
bool m_running = false;
ManualResetEvent m_event = new ManualResetEvent(true);
bool m_pause = false;
private GraphPane myPane;
public Form1()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
SearchPorts();
CreateZedGraph();
}
private void btnStart_Click(object sender, EventArgs e)
{
if (m_thread == null || m_thread.IsAlive == false)
{
ClearGraph();
m_thread = new Thread(Process);
m_thread.Start();
}
}
void Process()
{
PointPair point = new PointPair();
btnStart.Enabled = false;
btnStop.Enabled = true;
m_running = true;
while (m_running == true)
{
m_event.WaitOne();
point.Y = Convert.ToDouble(serialPort1);
point.X++;
DrawPoint(zed1, point);
ssData.Value = point.Y.ToString();
RefresheZedGraphs(zed1);
Thread.Sleep(700);
}
btnStart.Enabled = true;
}
private void CreateZedGraph(object sender, SerialDataReceivedEventArgs e, ZedGraphControl zgc)
{
myPane = zgc.GraphPane;
myPane.Title.Text = "FRDM-KW40z serial Test";
myPane.XAxis.Title.Text = "Time";
myPane.YAxis.Title.Text = "Voltage";
myPane.XAxis.MajorGrid.IsVisible = true;
myPane.YAxis.MajorGrid.IsVisible = true;
myPane.XAxis.MinorGrid.IsVisible = true;
myPane.YAxis.MinorGrid.IsVisible = true;
PointPairList list = new PointPairList();
zed1.GraphPane.AddCurve("Test", list, Color.Red);
}
private void button2_Click(object sender, EventArgs e)
{
comboBox1.Items.Clear();
SearchPorts();
}
void SearchPorts()
{
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
{
comboBox1.Items.Add(port);
}
}
private void button3_Click(object sender, EventArgs e)
{
OpenCloseSerial();
}
void OpenCloseSerial()
{
try
{
if (sp == null || sp.IsOpen == false)
{
t = comboBox1.Text.ToString();
sErial(t);
button3.Text = "Close Serial port";
}
else
{
sp.Close();
button3.Text = "Connect and wait for inputs";
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
void sErial(string Port_name)
{
try
{
sp = new SerialPort(Port_name, 115200, Parity.None, 8, StopBits.One);
sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
sp.Open();
}
catch (Exception err)
{
throw (new SystemException(err.Message));
}
}
private void DataReceivedHandler(object sender,SerialDataReceivedEventArgs e)
{
if (e.EventType == SerialData.Chars)
{
if (sp.IsOpen)
{
string w = sp.ReadExisting();
if (w != String.Empty)
{
Invoke(new Action(() => Control.Update(w)));
}
}
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (sp == null || sp.IsOpen == false)
{
OpenCloseSerial();
}
}
I get an error at : Invoke(new Action(() => Control.Update(w))); when trying to update the graph so that I can save after that.
I again have an error at: DrawPoint(zed1, point);
Thank you all for your time. Good day.
Cheers, Ram.
|
|
|
|
|
please don't post your question in multiple forums - once will do
|
|
|
|
|
sorry for the trouble, I thought this is the correct forum. Forgot about the tags
|
|
|
|
|
You turn "off" cross-thread call checking ... while (apparently) doing cross-thread calls.
Don't see where you're doing an "Invoke" either ... while using a DispatcherTimer will probably yield better results since it runs on the ui thread.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi, Thanks for the reply. I think zedgraph is too much for me to understand. I will follow your advice. I will also try using a chart instead.
Cheers,
Ram.
|
|
|
|
|
Good plan. The DispatcherTimer allows for a simpler "time based / event driven" approach to applications that "sample" on a periodic basis and need to update the UI (i.e. temperature charting).
If you haven't already, here's a great MS Chart resource (I use the chart in WPF apps):
Windows Forms Samples Environment for Microsoft Chart Controls in C# for Visual Studio 2010
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
In the C# Windows Service we develop, we need to refer a dll file from a different folder, for an API Method call of a method in the dll. This we want to accomplish by directly accessing the folder where the dll exists. Also, we do not want the dll to be copied into the folder where the Executable file of the Windows Service is available.
Example, we have a windows service called IdMAccountService,with it's Executable file IdMAccountService.exe available in D:\MetraTech\RMP\BIN folder . In that service we are referencing a dll file D:\MetraTech\RMP\Extensions\Account\Bin\MetraTech.Account.ClientProxies.dll for an API Method Call.
Is it possible for us to do it without copying the above dll to D:\MetraTech\RMP\BIN folder?
For this, I tried setting the ‘Copy Local’ as False in the reference to the dll and tried creating the Shortcut of the DLL file in the D:\MetraTech\RMP\BIN folder.
On both the cases, Service while executing gives the error as 'Error Could not load file or assembly 'MetraTech.Account.ClientProxies, Version=0.0.0.0, Culture=neutral, PublicKeyToken=a0f5c26dbec45a75' or one of its dependencies. The system cannot find the file specified.'.
I would like to know how I can make it work as expected? Please clarify.
Thanks & Regards,
Govindarajan K.
|
|
|
|
|
You could always use the AssemblyResolve[^] event which will be triggered when it can't find the assembly in the current path.
This space for rent
|
|
|
|
|
You can specify the location of strongly named assemblies in an application configuration file. I think doing so creates a maintenance nightmare but if you want to try it here are the details.
Add a application configuration file to the project and add the following
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MetraTech.Account.ClientProxies"
publicKeyToken="a0f5c26dbec45a75"/>
<codeBase version="0.0.0.0"
href="D:\MetraTech\RMP\Extensions\Account\Bin\MetraTech.Account.ClientProxies.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
The location of the assembly is hard coded which is less than ideal and a slight improvement is possible by specifying a relative path in the codeBase href attribute. If application base directory is D:\MetraTech\RMP\BIN then this should be correct.
<codeBase version="0.0.0.0"
href="..\Extensions\Account\Bin\MetraTech.Account.ClientProxies.dll"/>
If the ClientProxies.dll relies upon other assemblies within ..\Extensions\Account\Bin then a dependentAssembly element must be added for each one otherwise the assembly loader will only look in the GAC or the application base directory.
Good luck and remember that all the xml is case sensitive. If you enter PublicKeyToken instead of publicKeyToken then the loader won't complain and will just quietly ignore the whole dependentAssembly element.
Alan.
|
|
|
|
|
Thanks Alan for the inputs provided. It worked fine for me.
Govind.
|
|
|
|
|
I found an Unexplainable behaviour of LINQ in a tutorial code example from this site:
How to: Populate Object Collections from Multiple Sources (LINQ) (C#)
https:
How to: Join Content from
starting from 2 Files:
names.csv
-----------------------------------
Omelchenko,Svetlana,111
O'Donnell,Claire,112
Mortensen,Sven,113
Garcia,Cesar,114
Garcia,Debra,115
Fakhouri,Fadi,116
Feng,Hanying,117
Garcia,Hugo,118
Tucker,Lance,119
Adams,Terry,120
Zabokritski,Eugene,121
Tucker,Michael,122
scores.csv
-----------------------------------
111, 97, 92, 81, 60
112, 75, 84, 91, 39
113, 88, 94, 65, 91
114, 97, 89, 85, 82
115, 35, 72, 91, 70
116, 99, 86, 90, 94
117, 93, 92, 80, 87
118, 92, 90, 83, 78
119, 68, 79, 88, 92
120, 99, 82, 81, 79
121, 96, 85, 91, 60
122, 94, 92, 91, 91
Code:
class Student
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int ID { get; set; }
public List<int> ExamScores { get; set; }
}
public static void Main()
{
string filepathname = @"C:\LINQPad\";
string[] names = System.IO.File.ReadAllLines(filepathname + "names.csv");
string[] scores = System.IO.File.ReadAllLines(filepathname + "scores.csv");
IEnumerable<Student> queryNamesScores =
from nameLine in names
let splitName = nameLine.Split(',')
from scoreLine in scores
let splitScoreLine = scoreLine.Split(',')
where splitName[2] == splitScoreLine[0]
select new Student()
{
FirstName = splitName[0],
LastName = splitName[1],
ID = Convert.ToInt32(splitName[2]),
ExamScores = (from scoreAsText in splitScoreLine.Skip(1)
select Convert.ToInt32(scoreAsText)).
ToList()
};
List<Student> students = queryNamesScores.ToList();
foreach (var student in students)
{
Console.WriteLine("The average score of {0} {1} is {2}.",
student.FirstName, student.LastName,
student.ExamScores.Average());
}
}
Expected Output:
The average score of Omelchenko Svetlana is 82.5.
The average score of O'Donnell Claire is 72.25.
The average score of Mortensen Sven is 84.5.
The average score of Garcia Cesar is 88.25.
The average score of Garcia Debra is 67.
The average score of Fakhouri Fadi is 92.25.
The average score of Feng Hanying is 88.
The average score of Garcia Hugo is 85.75.
The average score of Tucker Lance is 81.75.
The average score of Adams Terry is 85.25.
The average score of Zabokritski Eugene is 83.
The average score of Tucker Michael is 92.
*/
* Real Output:
… nothing ….
*/
Why does LINQ not match correctly
At this point of code:
where splitName[2] == splitScoreLine[0]
And therefore no output will be generated
Thanks for advice
Alberto
ALBAB
|
|
|
|
|
When testing strings for equality, white-space is important. It looks like you've got extra spaces at the end of each line in both files. Since you're comparing the last field of one file to the first field of the other, the extra white-space means they'll never match.
For example, "112 " is not equal to "112" .
Remove the extra spaces from the files, or trim the strings before comparing them.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you, this solved of course the "problem".
It is something so obvious, but what an inattention of my side.
ALBAB
|
|
|
|
|
Hi fellow CP'ians,
i encountered a "problem" i am a bit shy to try my self. I am creating a localizible application (WinForms) which means i use the designer to create the UI for the different languages. Now, since i have ReSharper, i encountered the "problem" that the resx files either contain duplicates which are not overvritten or contain stuff which is not depending on localization. This hands me a lot of "possible code quality issues" which i understand seems reasonable. But how would i get rid of those except for telling ReSharper to ignore it?
My Question therefore is that is it possible to delete those lines in the resx files and if needed set the values in the designer.cs ? I have no idea how deep the resx files go and how they work 100% so any advice / experience you have would be a great help
Thanks in advance
Rules for the FOSW ![ ^]
if(this.signature != "")
{
MessageBox.Show("This is my signature: " + Environment.NewLine + signature);
}
else
{
MessageBox.Show("404-Signature not found");
}
modified 7-Mar-17 4:13am.
|
|
|
|
|
resx files are "name-value" pairs.
Unless someone used "non-standard" access methods, you should be able to to a "global search" of the "solution" files for the "name" keys to see if they are being referenced.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I think you got me wrong on this, im not talking about the stuff you see when you open a .resx file in visual studio normally. Im talking about the XML behind it like :
<data name=">>_mainMenu.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="_explBarProjInfo.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
</data>
<data name="_lbCustomerName.Text" xml:space="preserve">
<value>Customer Name :</value>
</data>
Where the _lbCustomerName.Text value is reasonable for the sake of translations, the ZOrder and the Dock are not necessary for localization as the UI shall not look different. Therefore i was asking about those parts (which are actually auto generated) to be deletable.
Rules for the FOSW ![ ^]
if(this.signature != "")
{
MessageBox.Show("This is my signature: " + Environment.NewLine + signature);
}
else
{
MessageBox.Show("404-Signature not found");
}
|
|
|
|
|