|
For starters, look at your code:
if (opf.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(opf.FileName);
}
Bitmap bmp = new Bitmap(opf.FileName);
pictureBox1.Image = Image.FromFile(opf.FileName);
Why are you doing that? Any of that, really?
If the OK button is pressed you load an image from a file. Then you load it again, and throw that away. Then you load it again and stuff it over the top of the first one you loaded.
If the Cancel button is pressed, you load the image (which will probably fail because there is no filename in the dialog) throw that away, and load it again (failing again) and muck up your picture box anyway...
Throw away the last two lines of that code. Then if and only if the user pressed OK
1) Load the image from the file
2) Copy the image into a new image and Dispose the original
3) Then set the copy as the PictureBox.Image
The reason for that is that when you create an image from a file, it locks the file until the Image is Disposed - so you need to work with a copy 99% of the time or your code fails in interesting ways later!
Then handle the PictureBox.Paint event. Inside that, you can use the supplied Graphics Context to draw over the Image using:
Graphics.DrawLine Method (Pen, Point, Point) (System.Drawing)[^] Call it three times fro your triangle.
Graphics.DrawRectangle Method (Pen, Int32, Int32, Int32, Int32) (System.Drawing)[^] Call it once to draw your rectangle.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks for your reply. My point is I want to display to the picturebox2 of an square shape at the center of the plain white image when I click the button Square.
|
|
|
|
|
Then don't load the image from a file: create a new Bitmap of the right dimensions.
Then use the Graphics.FromImage method in a using block to get the context to draw on.
Use Graphics.FillRectangle to draw it as a solid white background.
Then use Graphics.DrawRectangle to draw your square.
Finally, set the Bitmap as the Image for the PictureBox.
Use a very similar process to draw your triangle with Graphics.DrawLine
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I would personally not even try to load an image. If the only reason is that you need a white background, use a panel and define the background as white. That means one less point of potential failure.
To draw on that panel you can create a "Graphics" object with the handle of that panel.
You'll need to read up on the Graphics classes, which contains many methods to draw similar like the Paint application does on your windows machine.
Hope this helps.
|
|
|
|
|
my table structures are
Customer
----------
CustomerID
FirstName
LastName
PhoneNo
Email
Order
--------
CustomerID
OrderID
OrderStatus
OrderDate
TotalPrice
OrderDetails
------------
ID
OrderID
ProductID
Qty
so now i have to show
CustomerID,FirstName,LastName,PhoneNo,Email and OrderCount
please give me a sample EF linq query
thanks
|
|
|
|
|
I'm curious, what do you think your query should look like? Have a try and come back with any problems that you encounter.
This space for rent
|
|
|
|
|
i write sql but not very good with linq to compose my below query. it will be great help if some one give me some hint
SELECT CustomerID,FirstName,LastName,PhoneNo,Email and count(*) as OrderCount
FROM Customers
INNER JOIN Orders ON Customers .CustomerID = Orders .CustomerID
GROUP BY CustomerID,FirstName,LastName,PhoneNo,Email
WHERE CustomerID=101
i compose this but take help from google search. see my sql and linq query and tell me does it give me my desired result
var data = (from c in db.customers
join o in db.orders
on c.CustomerID = o.CustomerID into subs
from sub in subs.DefaultIfEmpty()
group sub by new { c.CustomerID, c.FirstName,c.LastName,c.PhoneNo,c.Email } into gr
select new {
gr.Key.CustomerID,
gr.Key.FirstName,
gr.Key.LastName,
gr.Key.PhoneNo,
gr.Key.Email,
OrderCount = gr.Count(x => x != null)
}).ToList();
please help me if any rectification is required. thanks
|
|
|
|
|
Something like this should work:
var data = db.Customers
.Where(c => c.CustomerID == 101)
.Select(c => new
{
c.CustomerID,
c.FirstName,
c.LastName,
c.PhoneNo,
c.Email,
OrderCount = db.Orders.Count(o => o.CustomerID == c.CustomerID)
})
.ToList();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
thank you so much sir for sharing right query with me
|
|
|
|
|
Hi friends,
I need good graphic library for C# ,is it available like QCustomPlot
|
|
|
|
|
I've searched everywhere and found in VB, but it does not work.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim aakam031 As String = My.Computer.FileSystem.SpecialDirectories.Temp
Dim akam As String = aakam031 + "filename pashgr"
IO.File.WriteAllBytes(akam, My.Resources.file name)
Process.Start(akam)
End Sub
End Class
Anyone know how to do it in C #
modified 17-Jan-18 20:51pm.
|
|
|
|
|
Quote: it does not work. This is not a helpful error summary, - it tells us nothing bout what the problem is. All is says is "I have a problem" - but we know that already because you are asking a question!
The other things that don't help are:
1) Showing code that you didn't try - because VB code won't compile in a C# program we have no idea what actual code you did try
2) Not explaining what the code is meant to do: I have no idea what "open a flush" is supposed to mean!
So show us the code you tried; tell us what happened that you didn't expect, or didn't happen that you did; tell us what you did to cause that to happen; explain what you expected the code to do; Tell us what you tried to find out why it did what ti did. Have you used the debugger? If not, why not? If so, what did it show?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
So this code is to run a program that i, we carry inside the project, in that resource folder.
but he is like you and I want him as C # I put it to convert more it does not work
And it's not flush, the broker showed it wrong, I meant program or file
|
|
|
|
|
|
|
And how would you do that? you can leave a sample code or sample link
|
|
|
|
|
see my sample code
public class PersonalDetail
{
public int Id { get; set; }
public string FirstName { get; set; }
public int Age { get; set; }
}
public ActionResult Index()
{
List<PersonalDetail> oPersonalDetail = new List<PersonalDetail>
{
new PersonalDetail {FirstName="Tapan",Age=11},
new PersonalDetail {FirstName="Joy",Age=21},
new PersonalDetail {FirstName="Madhu",Age=31}
};
return View();
}
when oPersonalDetail is populate then i want id should be populate automatically with 1,2,3....son on. so please guide me how could i achieve it ?
|
|
|
|
|
Assuming this is a one-time value (i.e. your data isn't persisted in a database or similar), add a class level static integer to your class, and initialize it to one:
private static int nextValue = 1; Then in your class constructor, you set the Id value to the static variable, and increment:
public PersonalDetail()
{
Id = nextValue++;
} Do note that this is not inherently thread safe, so if you need a complex program you need to look at more robust schemes - but then you are probably going to be using a database of some form to store your data instead of hardcoding it, and all databases provide mechanisms for supporting unique values for each row so that should be a concern.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You have to:
- Add a
static private member variable that holds the last assigned ID
- Provide a constructor that increments the last ID and assigns the value to
Id
- Make the incrementing and copying of the last ID member thread safe (e.g. using
Interlocked.Increment )
- Make the set method for
Id private
Possible implementations are shown in this SO thread: C# Class Auto increment ID - Stack Overflow[^]
|
|
|
|
|
If your data is going to be saved to a database, the chosen database system software can automatically assign id's / sequence numbers for you. The id is assigned when the data is added to the database.
Otherwise, any "ascending" / unique number usually will do; like a timestamp (e.g. machine + yyyymmddhh.....)
Managing "sequence numbers" yourself is usually more pain than it's worth. e.g. Running the same software on different computers usually creates "duplicates" "across" systems.
Always consider the long-term.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Until we understand your intent better, particularly why you used the reserved word 'Index ... and the unexplained method result 'ActionResult, and how 'View is a return value for the method ... well, we are not psychics.
So, clarify what you are trying to do.
«... 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
|
|
|
|
|
my intention is not to mention id value when populate my class and id value will be generated automatically and incremented by 1 always. thanks
|
|
|
|
|
The context is what matters here: depending on context I might:
1. if the value of 'Id is local to the class, then a static class Int32 variable incremented in the constructor is all you need.
1.a. if you need to keep a collection of instances of 'PersonalDetail:
public class PersonalDetail
{
public PersonalDetail(string firstName, int age)
{
if (IdToInstance.Any(kvp => kvp.Value.FirstName.Equals(firstName)))
{
throw new DuplicateNameException();
}
FirstName = firstName;
Age = age;
IdToInstance.Add(Id++, this);
}
public string FirstName { get; set; }
public int Age { get; set; }
static PersonalDetail()
{
Id = 1;
IdToInstance = new Dictionary<int, PersonalDetail>();
}
static int Id { set; get; }
static Dictionary<int, PersonalDetail> IdToInstance { get; }
public static void Add(params (string name, int age)[] pds)
{
foreach (var pd in pds)
{
new PersonalDetail(pd.name, pd.age);
}
}
public static PersonalDetail InstanceFromId(int id)
{
PersonalDetail pd = null;
return IdToInstance.TryGetValue(id, out pd) ? pd : null;
}
}
2. if 'Id is also used by other classes, or can be changed for a given instance: for that, I would consider a static Id manager class.
«... 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
|
|
|
|
|
I'm creating a tool for android, where I would like to create a button that would run the adb or fastboot command and display it on the console.
Most do not know how to import the files into the program and be executed by it, not in having to export the files somewhere to run.
Can you do that?
Another question is how do I download and install a direct program from the site?
the program would be java
Here I have an image as the tool would be
<a href="https://prnt.sc/i1i7y8">Screenshot_1</a>
|
|
|
|
|
Your question is not clear. These commands are part of the Android SDK and run on the PC not the Android device.
Member 13621117 wrote: how do I download and install a direct program from the site? What site are you talking about here?
|
|
|
|