|
@User-14042352
If you are trying to "seamlessly" scale a WinForm UI ... and I recommend you don't ... this is an excellent resource: [^].
Remember that most fonts have (internally) special "optical tunings" to look good at certain discrete sizes/weights.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
hey trying to get my code to dispaly a times table but it just comes out in a straight line
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestLibary;
namespace ICA25
{
class Program
{
static void Main(string[] args)
{
string sTitle;
bool bExit = false;
sTitle = ("ICA 25 - Times table");
Console.WriteLine("{0,60}\n", sTitle);
do
{
{
int[,] iFinal;
int iNum = GetValue("Please enter the size (4-20) of the times table: ", 4, 20);
Console.Write("Here is the times table for that size: \n");
iFinal = GenerateTT(iNum);
DisplayTT(iFinal);
}
}
while ((YesNo("Would you like to do another? Y or N:") == "Y") && !bExit);
bExit = true;
}
static public int GetValue(string s, int iMin, int iMax)
{
int iNum;
Utilities.GetValue(out iNum, s, 4, 20);
return iNum;
}
static public int[,] GenerateTT(int iValue)
{
int[,] iNum = new int[iValue, iValue];
for (int iRow = 0; iRow < iNum.GetLength(0); iRow++)
{
for (int iCol = 0; iCol < iNum.GetLength(1); iCol++)
{
iNum[iRow, iCol] = (iCol) * (iRow);
}
}
return iNum;
}
static public void DisplayTT(int[,] iFinal)
{
for (int iRow = 0; iRow < iFinal.GetLength(0); iRow++)
{
{
for (int iCol = 0; iCol < iFinal.GetLength(1); iCol++)
{
Console.Write( iFinal[iRow, iCol]);
{
Console.WriteLine();
}
}
}
}
}
static public string YesNo(string sPrompt)
{
string stemp;
do
{
Console.Write("{0}", sPrompt);
stemp = Console.ReadLine().ToString().ToUpper();
if (stemp == "N")
{
Console.Write("Bye");
Console.ReadLine();
}
if (stemp != "Y" && stemp != "N")
{
Console.Write("\nPlease answer Y or N.");
}
}
while ((stemp != "Y") && (stemp != "N"));
return stemp;
}
}
}
|
|
|
|
|
Hi,
1.
the way you set things up, every Console.Write is followed by a Console.WriteLine, so you will never get two adjacent numbers: every number will take a new line.
2.
Writing
Console.Write( iFinal[iRow, iCol]);
{
Console.WriteLine();
}
and writing
Console.WriteLine( iFinal[iRow, iCol]);
is absolutely equivalent.
3.
you fooled yourself by using a lot of redundant brackets. The compiler doesn't mind, but you lost track of what is inside the inner for loop and what isn't.
4.
Once you fix the problem, you'll find out you're not there yet, as Write() or WriteLine() will use whatever number of positions is required to represent the number, so the table may well be badly aligned. If so, start looking at some overloads of int.ToString() .
modified 10-Oct-19 19:33pm.
|
|
|
|
|
Dear CodeProject members,
Hope you can help with the second code that i'm struggling as the other one was answered.
I'm new to C# and compiled this code but I'm stuck and getting error Argument 1: cannot convert from 'System.Management.MamangementScope' to 'string' which is in bold and underlined below
my references are
using System;
using System.Linq;
using System.Management;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
private void WMI_Click(object sender, EventArgs e)
ManagementObjectSearcher objSearcher = null;
ManagementObjectCollection objCollection = null;
ManagementScope objScope = null;
ManagementQuery objQuery = null;
ConnectionOptions objOptions = null;
objOptions = new ConnectionOptions();
objOptions.Impersonation = ImpersonationLevel.Impersonate;
//options.Username = "Username";
//options.Password = "Password";
//options.Authority = "NTLMDOMAIN:DOMAIN";
objScope = new ManagementScope("\\\\Computer\\root\\cimv2:", objOptions);
objScope.Connect();
objQuery = new ObjectQuery("SELECT * FROM Win32_PnPEntity");
objSearcher = new ManagementObjectSearcher(objScope, objQuery);
objCollection = objSearcher.Get();
//objQuery = new ManagementQuery ("SELECT * FROM Win32_PnPEntity");
Thank you and much appreciate your help.
|
|
|
|
|
In your variable declarations, change "ManagementQuery" to "ObjectQuery". You cannot declare an instance variable as an abstract class type and then start calling methods and setting properties on it as the abstract class won't have implementations of those properties and methods.
ManagementObjectSearcher objSearcher = null;
ManagementObjectCollection objCollection = null;
ManagementScope objScope = null;
ObjectQuery objQuery = null;
ConnectionOptions objOptions = null;
modified 9-Oct-19 15:10pm.
|
|
|
|
|
Thank you to all and to Dave thank you for correcting me.
Now i'm very happy to have completed this code.
I thank all of you again for helping.
Wish you a lovely day
|
|
|
|
|
|
I spun a quick project and copy'n'pasted the OP's code into it. Sure enough, he's got the exact error message and the line in comes up on correct.
It took me an embarrassing number of minutes staring at it before I looked up the ManagementObject class and saw it was an abstract. Then it all clicked.
|
|
|
|
|
Hi Dave and Richard, thank you for checking my code.
Richard yes that is error I’m getting and thank you trying Dave.
I’m stuck and will have to check Microsoft links tomorrow at work like I said it is my first time and I’m stuck and don’t understand.
Dave since you tried and saw the errors would you be kind to highlight where I’m going wrong so that I can learn from please but if you think it’s better to read the links then I would do that but if I’m not mistaken I got some of the code from Microsoft to understand and I tried but without success.
Thank you and have a great evening.
|
|
|
|
|
He told you exactly what to do in his original reply!
Did you try it 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!
|
|
|
|
|
Thank you Griff, Sorry as I’m new to this forum I apologize I didn’t see the first reply he did and I will try it tomorrow morning 🙏.
Thank you and wish you a lovely evening.
|
|
|
|
|
Hi All,
Is there a simple C# Dot Net API available to record AVI files for a given set of BMP images ?
Would appreciate any code samples that shows the usage of such an API !
Thanks In Advance !
|
|
|
|
|
Check the .NET documentation, and also Google.
|
|
|
|
|
|
What do you mean by "column header sort doesn't work"?
Please show your sort method, and explain which part of it has the problem.
|
|
|
|
|
I want to number the dataGgridView but it doesn't work, you see the red rectangular image file
|
|
|
|
|
The image you have posted is not viewable and cannot be downloaded without creating a Mediafire account. Please post the actual code in your original question and explain what the error is and where it occurs.
|
|
|
|
|
I will post code does not work, I will post my code for you to see, what am I wrong with ?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.dataGridView1.VirtualMode = false;
this.dataGridView1.SortCompare += new System.Windows.Forms.DataGridViewSortCompareEventHandler(this.dataGridView1_SortCompare);
dataGridView1.DataSource = CreateTable(5);
}
private static DataTable CreateTable(int RowCount)
{
DataTable tbl = new DataTable();
tbl.Columns.Add("check1", typeof(bool));
tbl.Columns.Add("ID", typeof(int));
tbl.Columns.Add("Name", typeof(string));
tbl.Columns.Add("Number", typeof(int));
tbl.Columns.Add("Date", typeof(DateTime));
tbl.Columns.Add("check2", typeof(bool));
for (int i = 0; i < RowCount; i++)
tbl.Rows.Add(new object[] { false, i, String.Format("Name{0}", i), 3 - i, DateTime.Now.AddDays(i), true });
return tbl;
}
private void dataGridView1_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
e.SortResult = System.String.Compare(
e.CellValue1.ToString(), e.CellValue2.ToString());
if (e.SortResult == 0 && e.Column.Name != "ID")
{
e.SortResult = System.String.Compare(
dataGridView1.Rows[e.RowIndex1].Cells["ID"].Value.ToString(),
dataGridView1.Rows[e.RowIndex2].Cells["ID"].Value.ToString());
}
e.Handled = true;
}
}
image file http://www.mediafire.com/view/9ogb4uwvfr2ag3i/dgv2.jpg/file
|
|
|
|
|
|
all the code I copied from microsoft company, even the top of the page I posted without you reading my first questions, now you give the same link from microsoft company. Before you criticize others, have you tried my example ?
|
|
|
|
|
I posted that link to emphasise the point that you were using the Microsoft code. However, you have still, despite three requests, not explained what your problem is.
[edit]
And to answer your question, yes I have tried the example, and it works fine.
[/edit]
|
|
|
|
|
I found out why the dataGridView1_SortCompare method doesn't allow dataGridView1.DataSource to be assigned if using the sort feature.
|
|
|
|
|
Using the DataContract serialize/deserialize facilities in System.Runtime.Serialization is very convenient, reliable. It does produce verbose xml with rather stunningly long labels like:
</KeyValueOfPersonLikeIntensityvlZcIX2K></Value></KeyValueOfPersonArrayOfKeyValueOfPersonLikeIntensityvlZcIX2Kg_S_SinKSu></ArrayOfKeyValueOfPersonArrayOfKeyValueOfPersonLikeIntensityvlZcIX2Kg_S_SinKSu> That's serialized output from a graph engine I am writing. However, by using GZip you can compress that by factors of #20, or more.
It is interesting to observe that if a Class inherits from a generic structure, like:
[DataContract]
public Class Graph<TVertex, TEdge> : Dictionary<TVertex, Dictionary<TVertex, TEdge>> That will fail to serialize; however, by removing the 'DataContract Attribute, and adding the 'Serializable Attribute, it will serialize properly using a 'DataContractSerializer. This works:
[Serializable]
public Class Graph<TVertex, TEdge> : Dictionary<TVertex, Dictionary<TVertex, TEdge>> And, you can, of course still have the Class as generic, and make an internal field/property of the necessary Type marked with the 'DataMember Attribute:
[DataContract]
public Class Graph<TVertex, TEdge>
{
[DataMember]
public Dictionary<TVertex, Dictionary<TVertex, TEdge>> GraphDict { set; get; }
} I haven't seen any documentation on this, but the error message is what suggested trying to replace 'DataContract with 'Serializable:
System.Runtime.Serialization.InvalidDataContractException
HResult=0x80131500
Message=Type 'Graph_2019_2.PersonLikeGraph' cannot be ISerializable and have DataContractAttribute attribute. So, you be the judge: hack, or useful information ? Anomalous but reliable, or, anomalous and unreliable ?
Note: while the observations I cite are all based on FW 4.8: the behavior described has been encountered with many previous FW versions.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 8-Oct-19 14:17pm.
|
|
|
|
|
BillWoodruff wrote: So, you be the judge: hack, or useful information ? Anomalous but reliable, or, anomalous and unreliable ? Since it is not documented, I'd say such behaviour might change between releases. For MS, anything undocumented is unsupported and "subject to change".
I wouldn't rely on it for anything in production. Does your engine require it, or can you live without?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|