|
All you need is to decide a couple of things, given dX, dY as the usable width and height of the panel inside any edge margins, and R, C are the number of rows and columns.
First pick how big a margin M you want around each panel (we'll assume that M is the same top and side)
width of each image = (dY - (C - 1) * M) / C
height of each image = (dY - (R -1 ) * M) / R Now all you need to do is nest two loops, and create your PictureBoxes, setting the Size of each to (width, height) and the Location to (columnNumber * (width + M), rowNumber * (height + M)) (both offset by the margin round the edges of the panel, obviously)
Then add each PictureBox to the Panel.Controls collection.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
thank you i find a way to create it !
private void btnGenerate_Click(object sender, EventArgs e)
{
panel3.Controls.Clear();
int rows = Convert.ToInt32(txtRows.Text);
int columns = Convert.ToInt32(txtColumns.Text);
PictureBox[,] map = new PictureBox[rows,columns];
for (int j = 0; j < columns; j++)
{
for (int i = 0; i < rows; i++)
{
System.Threading.Thread.Sleep(50);
map[i, j] = new PictureBox();
map[i, j].Width = 45;
map[i, j].Height = 45;
map[i, j].BackColor = Color.NavajoWhite;
if (i == 0 && j == 0)
{
map[i, j].Location = new Point(100, 100);
}
map[i, j].Location = new Point(45 * i + 100, 45 * j + 100);
map[i, j].BorderStyle = BorderStyle.Fixed3D;
panel3.Controls.Add(map[i, j]);
}
}
}
|
|
|
|
|
what is the best way to process image i have a scenario i have floor map of parking and first i want to allocate as an available slot in the system once it is available slot i need to assign it to one of the staff once assign i want to show this area as red and available slot as green on this floor image. kindly assist me that what is the best way to implement this in C# ASP.NET.
Thanks in advance.
|
|
|
|
|
What have you tried?
Where are you stuck?
What help do you need?
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. And you haven't told us much at all ...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
If I were doing this, given several assumptions about what you are asking, I'd probably do it using Scalable Vector Graphics (SVG).
This space for rent
|
|
|
|
|
Hi all!
New to the forum
I have a made a application that stores it's settings with the following code:
Properties.Settings.Default.Username= TxtUsername.Text;
Properties.Settings.Default.Password = TxtPassword.Text;
Properties.Settings.Default.Tel = TxtTel.Text;
Properties.Settings.Default.EMail = TxtEMail.Text;
Properties.Settings.Default.Save();
Loading the settings works just fine, but with one exception.
If I change the code in any way, the settings changes to "\r\n\t\t\t\t".
I can image it is because the application has changed or something like that.
But is there any way to make it so it changes to "" instead?
Want to make a function to check if the settings have been set by checking each of them if they are null. Dosent work that well if they either are null or contain "\r\n\t\t\t\t".
Note that I am using SharpDevelop, I am at work and I can't get VS Studio here, unfortunatly.
|
|
|
|
|
I am a 100% online student trying to learn C#. My instructor has not been of help, so I am looking for help elsewhere.
My homework is to create a program that will convert measurements:
"
In the English measurement system, 1 yard equals 3 feet and 1 foot equals 12 inches. Use this information to create an application that lets the user convert distances to and from inches, feet, and yards. Use list boxes for the user to select units being converted from and another list box for the user to select units being converted from.
Write your code in the following order
Program must check for correct input into the textbox. Hint: use TryParse.
Check that user has selected a from unit. If not, let user know no unit has been selected.
Check that user has selected a to unit. If user selects the same unit for both from and to, let them know that they need to select a different unit. "
I believe I have my TryParse correct. It will make sure a measurement has been entered, a from distance has been selected and a to distance has been selected. After that, I am not sure where to proceed. I don't know how to grab what is selected in the from groupbox to the to groupbox and then convert. Any help would be appreciated. Thanks!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Distance_Converter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void convertButton_Click(object sender, EventArgs e)
{
double distanceInput;
double inches;
double feet;
double yards;
string measurementFrom;
if (double.TryParse(distanceTextBox.Text, out distanceInput));
{
if (fromListBox.SelectedIndex != -1)
{
if (toListBox.SelectedItem = != -1)
{
}
}
}
}
}
}
Image of UI: Capture — imgbb.com[^]
|
|
|
|
|
Your tryparse is correct but you are not doing the job asked of you, you test the input but do nothing if it is incorrect.
Do each test in isolation rather than nesting them.
Test that the input will parse as a double (add a message to a string if it fails)
Test that the distance input is not zero
Test that a from unit has been selected (add a message to a string if it fails)
test that a to unit has been selected
test that the selected unit type are not the same (have the same selectindex)
Tell the user of any errors in the testing phase
Use the selectedindex to get the unit type for each listbox from the underlying collection
You now have the distance, the from type and the to type. The conversion is a simple math operation.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm relearning C#, and due to my lack of funds, am using a computer that's over 5 years old and cannot even create console apps except using an online compiler. For some reason, Visual Studio will not create console apps. But that's beside the point.
I was given a file, and the task to sort out which items go on which shelf. It uses a lot of classes and arrays, my weak point in C#. So I thought I'd post here to see if someone could help me out with this.
The program itself is:
* At ACME warehouse the warehouse manager has observed orders taking a long time to pick and
* believes that moving more popular items to easier to access locations may help.
*
* - Workers pick an order by placing items on a pallet at the dock door.
* - Products are stored (inefficiently) in a single aisle with multiple shelves.
* - As the shelf number increases, it is located further down the aisle and
* further away from the dock door.
* - On average it takes 5*X seconds for a warehouse worker to retrieve an item
* from shelf X and place it on the pallet.
* - A warehouse worker can only carry a single item at a time.
* - A shelf can only hold one type of item.
*
* Which items should be on which shelves to optimize picking speed based on
* yesterday's orders?
*
*
* Example output
*
* Shelf 1: Item 12
* Shelf 2: Item 11
* Shelf 3: Item 10
* Shelf 4: Item 09
* Shelf 5: Item 08
* Shelf 6: Item 07
* Shelf 7: Item 06
* Shelf 8: Item 05
* Shelf 9: Item 04
* Shelf 10: Item 03
* Shelf 11: Item 02
* Shelf 12: Item 01
*
*/
OrderRepository orderRepo = new OrderRepository();
// write your code here
Console.WriteLine("Order " + Order[1].OrderLine[1]);
The functions are:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarehouseOptimization
{
public class Order
{
public OrderLine[] orderLines;
public int id;
public string customerName;
}
public class OrderLine
{
public int quantity;
public string itemName;
}
public class OrderRepository
{
public Order[] GetYesterdaysOrders()
{
Order[] orders = new Order[] {
new Order{
id = 1,
orderLines = new OrderLine[] {
new OrderLine{ itemName = "Item 01", quantity = 1},
new OrderLine{ itemName = "Item 02", quantity = 3},
new OrderLine{ itemName = "Item 03", quantity = 25},
new OrderLine{ itemName = "Item 04", quantity = 12},
},
},
new Order{
id = 2,
orderLines = new OrderLine[] {
new OrderLine{ itemName = "Item 01", quantity = 1},
new OrderLine{ itemName = "Item 08", quantity = 42},
new OrderLine{ itemName = "Item 09", quantity = 13},
new OrderLine{ itemName = "Item 12", quantity = 37},
},
},
new Order{
id = 3,
orderLines = new OrderLine[] {
new OrderLine{ itemName = "Item 12", quantity = 16},
},
},
new Order{
id = 4,
orderLines = new OrderLine[] {
new OrderLine{ itemName = "Item 10", quantity = 11},
new OrderLine{ itemName = "Item 11", quantity = 10},
},
},
new Order{
id = 5,
orderLines = new OrderLine[] {
new OrderLine{ itemName = "Item 06", quantity = 7},
new OrderLine{ itemName = "Item 07", quantity = 2},
new OrderLine{ itemName = "Item 12", quantity = 14},
},
},
new Order{
id = 6,
orderLines = new OrderLine[] {
new OrderLine{ itemName = "Item 05", quantity = 17},
},
},
new Order{
id = 7,
orderLines = new OrderLine[] {
new OrderLine{ itemName = "Item 03", quantity = 5},
new OrderLine{ itemName = "Item 07", quantity = 2},
},
},
new Order{
id = 8,
orderLines = new OrderLine[] {
new OrderLine{ itemName = "Item 02", quantity = 13},
new OrderLine{ itemName = "Item 07", quantity = 7},
new OrderLine{ itemName = "Item 09", quantity = 2},
},
},
new Order{
id = 9,
orderLines = new OrderLine[] {
new OrderLine{ itemName = "Item 01", quantity = 4},
new OrderLine{ itemName = "Item 06", quantity = 17},
new OrderLine{ itemName = "Item 07", quantity = 3},
},
},
new Order{
id = 10,
orderLines = new OrderLine[] {
new OrderLine{ itemName = "Item 11", quantity = 12},
new OrderLine{ itemName = "Item 12", quantity = 1},
},
},
};
return orders;
}
}
}
I used Excel to figure out the proper order for everything:
Quote: number item
68 12
42 8
30 3
24 6
22 11
17 5
16 2
15 9
14 7
12 4
11 10
6 1
With this, item 12 is most ordered, so it should go on shelf 1, and so on.
My question is how do I sort all this stuff program-wise?
Thanks in advance for your help.
|
|
|
|
|
So you have a collection of Order objects (class) each of which has a collection of OrderLine objects (class). You need to work with the total collection of OrderLine independent of the containing Order.
I would create another collection of Orderline and loop through the Order collection and add each OrderLine to the new collection
static void Main(string[] args)
{
OrderRepository oRepository = new OrderRepository();
List<Order> lOrders = oRepository.GetYesterdaysOrders().ToList();
List<OrderLine> oLines = new List<OrderLine>();
foreach (Order Item in lOrders)
{
oLines.AddRange(Item.orderLines);
}
Console.WriteLine(string.Format("Order Lines {0}", oLines.Count));
foreach (OrderLine oLine in oLines.OrderByDescending(x => x.quantity))
{
Console.WriteLine(string.Format("Item {0} Qty {1}", oLine.itemName,oLine.quantity));
}
Console.ReadLine();
}
The above code will give you an idea how to manipulate the collections - you need to research how to aggregate the collection to meet your needs.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
to do a project , SOAP webservice from client to server for sending work order and based on the request generate the response
|
|
|
|
|
And? Apart from that vague statement, do you actually have a question?
This space for rent
|
|
|
|
|
yes I don't know how to send variables and manage them on server side and send the result on client side
|
|
|
|
|
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
well I know that if I make a web service and a console application and connect them by reference it automatically generate and send requests as soap but I don't know how to define variables send it to the server and do process on them on server side and send the result to the client side
|
|
|
|
|
Hi,
I am looking to store my data that is not in a fixed format in an array or list but as array is of fixed size so cant use that, list provides flexibility but it doesnt comes with multi dimensions option like array does..
I had a data like:
"Acids", "A1", "A2", "A3" - this could grow to ph4 till ph 10 depends
"Sulphur" "S1", "S2", - this could grow to ph4 till ph 0 depends
"Carbon" "c1", C2" can grow depends
also after storing it in the list i also need to retrieve in a way that in a loop i should get first Acids then all its sub components that is A1, A2, A3, once done then move to Sulphur and get its corresponding components.
Please can anyone suggest anything on how to best deal with this.
|
|
|
|
|
How about a Dictionary<string, List<string>> ?
Dictionary with Single Key and Multiple Values Example in C#. See https://repl.it/CY3S/1 to run example code online. · GitHub[^]
Eg:
var data = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase)
{
["Acids"] = new List<string> { "A1", "A2", "A3" },
["Sulphur"] = new List<string> { "S1", "S2" },
["Carbon"] = new List<string> { "C1", "C2" },
};
if (!data.TryGetValue("Acids", out var acids)) acids = data["Acids"] = new List<string>();
acids.Add("A4");
if (data.TryGetValue("Sulphur", out var sulphur)) sulphur.Remove("S1");
foreach (KeyValuePair<string, List<string>> pair in data)
{
Console.WriteLine(pair.Key);
foreach (string value in pair.Value)
{
Console.WriteLine(value);
}
Console.WriteLine();
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
A list of lists is probably as close as you can get. Though it seems to me a lot less flexible, another option to consider is a dictionary where the key is an object or struct that stores the array subscripts. Since I suspect such a dictionary could get really ugly really fast, I would be inclined to use a list of lists.
David A. Gray
Delivering Solutions for the Ages, One Problem at a Time
Interpreting the Fundamental Principle of Tabular Reporting
|
|
|
|
|
I am making a Windows form program, where I use the AxMSTSCLib libery, the make a RDP session. Everything works fine, but I am having issues making some of the event handlers work, especially the "OnLogonError" event. It is not called as expected, when I type in wrong credentials.
I start out with this piece of code (have also tried the AxMsRdpClient8NotSafeForScripting version):
AxMsRdpClient9NotSafeForScripting RDP = new AxMsRdpClient9NotSafeForScripting();
RDP.OnLogonError += new AxMSTSCLib.IMsTscAxEvents_OnLogonErrorEventHandler(this.OnLogonError);
RDP.OnConnected += new EventHandler(axMsRdpClient2_OnConnected);
- and then later:
private void OnLogonError(object sender, AxMSTSCLib.IMsTscAxEvents_OnLogonErrorEvent e)
{
switch (e.lError)
{
case 0:
MessageBox.Show("The logon failed because the logon credentials are not valid.");
break;
default:
MessageBox.Show("An unknown error.");
break;
}
}
Private void axMsRdpClient2_OnConnected(object sender, EventArgs e)
{
MessageBox.Show("Connected!!!");
}
Do anyone experienced this problem? I have searched the Internet, but nothing useful regarding that some events are not called.
|
|
|
|
|
RDP.OnLogonError += new AxMSTSCLib.IMsTscAxEvents_OnLogonErrorEventHandler(this.OnLogonError);
RDP.OnConnected += new EventHandler(axMsRdpClient2_OnConnected);
You put this.OnLogonError and axMsRdpClient2_OnConnected for both parameter functions. Try to quit this (or base, if you call this in the Class) near the callback, maybe it works!
|
|
|
|
|
Thanks for your answer Matias, but I am not sure what you mean (near callback)? I have tried the line "RDP.OnLogonError += new AxMSTSCLib.IMsTscAxEvents_OnLogonErrorEventHandler(OnLogonError);" (without "this"), but still same result. I cannot use base, because the line is in the function, and not defined in the class.
|
|
|
|
|
If you put a Breakpoint in the CallFunction, can you debug it?
|
|
|
|
|
If am putting a breakpoint on the first line, where I create the "AxMsRdpClient9NotSafeForScripting", the it goes though my event lines, further down where I connect to RDP, and then I expect to come down to my "private void OnLogonError(object sender, AxMSTSCLib.IMsTscAxEvents_OnLogonErrorEvent e)" due to bad credentials, but it just dosent happen. It's like I have never defined the event call in the first place, so it just ignores it?
Also tried putting a breakpoint in the "private void OnLogonError(object sender, AxMSTSCLib.IMsTscAxEvents_OnLogonErrorEvent e)", but still I do not get to the error event.
modified 12-Sep-18 17:19pm.
|
|
|
|
|
After further testing, I found out that if connecting to a Windows 2003 server, the event is entered. But not when connecting to Win7 and newer and Win2008R2 and newer. I wonder if Microsoft removed the event functionality in newer systems?
|
|
|
|
|
I have a MySQL database with a table that has a TIMESTAMP field. All I need to do is get that value into a DateTime variable in C#.
I have a DataRow containing the timestamp value in column TimeStampCol (or it could be a datareader, same difficulty arises).
Have tried the following: (datarow in variable DR )
DateTime MyVar;
MyVar = (DateTime)DR["TimeStampCol"]);
MyVar = Convert.ToDateTime(DR["TimeStampCol"]);
MyVar = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(Double.Parse(DR["TimeStampCol"].ToString())).ToLocalTime()
I understand that the Timestamp is being returned as a long integer number, so am not surprised by the first two errors.
There's probably a .Net function to do this, but I can't find it... surely this should be a trivial operation?
Thanks!
|
|
|
|
|