|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid..
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
Hello,
first of all I just need a hint on how to approach this topic in the most sensible way.
I have an older application that can only determine its coordinates correctly when it is running on only one monitor. Now the application needs to run in environments with multiple screens with different resolutions. Example: Notebook with 1920x1080 + 3840×2160 + 1920x1200 (main screen). In addition, screens with a scaling other than just 100% can be run (e.g. 175%). As you can see here, a colourful mixture.
I would like to determine the exact position and window size of the program.
I am primarily a backend developer, so I have never had anything to do with this topic before. For this reason, I am turning to you in the hope of getting a push before I go the wrong direction.
Many thanks in advance and best regards
René
|
|
|
|
|
I have the following models:
public class User
{
[Key]
public int UserId { get; set; }
public string Name { get; set; }
public string LastName { get; set; }
public string? ImageUrl { get; set; }
public virtual List<Request> Requests { get; set; }
public virtual List<Message> Messages { get; set; }
}
public class Request
{
[Key]
public int RequestId { get; set; }
public DateTime RequestTime { get; set; } = DateTime.Now;
public bool? AcceptStatus { get; set; }
public User TargetUserRef { get; set; }
public User SenderUserRef { get; set; }
}
I want the Request table to have two foreign keys. I tried to use the following fluent API:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Request>()
.HasOne(m => m.SenderUserRef)
.WithMany(t => t.Requests)
.HasForeignKey(m => m.RequestId)
.OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<Request>()
.HasOne(m => m.TargetUserRef)
.WithMany(t => t.Requests)
.HasForeignKey(m => m.RequestId)
.OnDelete(DeleteBehavior.Restrict);
}
When I try to create migration, the following error is shown:
Quote: Cannot create a relationship between 'User.Requests' and 'Request.TargetUserRef' because a relationship already exists between 'User.Requests' and 'Request.SenderUserRef'. Navigations can only participate in a single relationship. If you want to override an existing relationship call 'Ignore' on the navigation 'Request.TargetUserRef' first in 'OnModelCreating'.
How can I solve this problem?
|
|
|
|
|
This is where you build the (test) "database first" and have EF generate the model it undertstands; instead of having to guess what your "model building" code is trying to do. Then you can try again with having some idea of what works.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
To me this is why relying on these sorts of APIs leads to problems.
Any API that attempts to simplify something always reduces complexity by removing features. That is of course the definition of simplification.
That works only as long as the needed usage is in fact simple. And more importantly that it is expected that over time it will remain simple.
If not then it will start to fail at some time. Then attempting to then use the API to solve the problem becomes a mess. Or perhaps even worse the API itself will introduce odd constructs with perhaps even odd restrictions and rules in an attempt to work around the original limitations. Those themselves will lead to problems over time.
|
|
|
|
|
Is it possible to highlight all rows in listbox between two index values?
If it possible how is it done?
|
|
|
|
|
Member 14055879 wrote: Is it possible to highlight all rows in listbox between two index values? Yes
Member 14055879 wrote: If it possible how is it done? By writing code. Beyond that answer, we can't really support you as there are too many open questions. What technology are you using here? WPF? WinForms? Maui? Platform x...? What do you mean by highlighting? Bolding the text? Changing the background colour? Causing the rows to blink?
When you ask a question of us, you have to remember that, unless you give us details, we don't know exactly what you want to achieve. Try to add as much detail as you can and that should help you get an answer closer to the one you want.
|
|
|
|
|
Surely someone as proficient at getting a
@ tag to make his post text stick out would have no troubles translating VBNET into C#: 50[^]
Wowie!
|
|
|
|
|
Assuming you are using a standard ListBox control in a graphical user interface (GUI) application, here is an example in Python using the Tkinter library:
# Let's say you have a ListBox named "my_listbox"
# First, get the start and end index values
start_index = 2
end_index = 5
# Next, iterate over the indices and change the background color
for i in range(start_index, end_index+1):
my_listbox.itemconfig(i, bg='yellow')
This code iterates over the indices between start_index and end_index (inclusive), and uses the itemconfig method to change the background color of each item to yellow. You can adjust the background color to whatever you like.
|
|
|
|
|
If I copy'n'paste your code into an online C# compiler:
using System;
public class Program
{
public static void Main()
{
string inputString = "A1+0001852Kg 054";
string weightValueString = inputString.Substring(3, inputString.IndexOf("Kg") - 3);
Console.WriteLine(weightValueString);
double weightKg = double.Parse(weightValueString) / 1000;
string formattedWeight = weightKg.ToString("N2");
Console.WriteLine(formattedWeight);
}
} And run it, I get what I expect:
0001852
1.85 Which means that the problem isn't the code: it's the input string that you are actually processing - and we have no access to that, to it's source hardware, or to the code that reads it from the machine.
So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
modified 16-Mar-23 3:19am.
|
|
|
|
|
|
You do have to wonder sometimes, don't you?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I'd say for the OP to use N3, rather than N2, but as I can't see the question on the page right now, I can't directly answer it.
|
|
|
|
|
That bit of code without the initial string assignment and the usual "It don't work" message I'm afraid.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Ah, the usual "here are all the steps I've tried, debugging operations I've undertaken, logs and traces", where the OP has reached out as a last resort eh?
|
|
|
|
|
And even delete his own question! Cleans up after himself.
|
|
|
|
|
I have an update process in my app that downloads an installer and runs it. If the user cancels the installer it throws a Win32Exception. The problem is that in the Catch all I get is the Exception with the message "The operation was cancelled by the user". Other than the text of the message, there's really no way to know for sure what exception occurred. I don't want to rely on the exception message.
Any way to trap this specific issue?
Here's my code:
private static void StartInstaller()
{
try
{
_ = Process.Start(_localSetupFile);
Process[] processes;
do
{
processes = Process.GetProcessesByName(_processName);
Thread.Sleep(1000);
}
while (processes.Length == 0);
}
catch (Win32Exception e)
{
}
catch (Exception e)
{
throw;
}
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Is the installer an .MSI?
|
|
|
|
|
Have you looked at ClickOnce? I have a Silent Updater for .Net Framework v3.5+ that takes out all of the hard work: Silent ClickOnce Installer for Winform & WPF in C# & VB[^]. If your app is Dot Net Core Framework, I have a new article that I will release very soon, just need to finish the article writeup.
Graeme
"I fear not the man who has practiced ten thousand kicks one time, but I fear the man that has practiced one kick ten thousand times!" - Bruce Lee
|
|
|
|
|
Win32Exception has a NativeErrorCode property which should return 1223 (0x4C7) when the user stops a process starting at a UAC prompt.
An example from my own code where I do something similar is probably clearer than more words!
private static void RestartWithRunAs(ProcessStartInfo psi) {
psi.UseShellExecute = true;
psi.ErrorDialog = true;
psi.Verb = "runas";
try {
Process.Start(psi);
} catch (System.ComponentModel.Win32Exception exc) {
const Int32 CancelledByUser = 1223;
if (exc.NativeErrorCode != CancelledByUser) {
throw;
}
}
}
See also
System Error Codes (1000-1299) (WinError.h) - Win32 apps | Microsoft Learn[^]
Alan.
|
|
|
|
|
Thanks. I'll give it a try
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
If this is not allowed please delete...
I'm looking for a programmer that can help me with a c# program I've started.
It's a CAD style program to design simple framework structures.
It's not a project for a larger development company, and I've tried websites that advertise professionals.
Mostly looking for help, but if someone is available to do more thats great too!!
Thanks,
Tom
|
|
|
|
|
This is not a recruitment site: I suggest you go to Freelancer.com and ask there.
But be aware: you get what you pay for. Pay peanuts, get monkeys.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Understood. That's why I began with delete if not permitted.
Not trying to recruit or poach. looking for help with a program I'm writing.
|
|
|
|