|
Good code is readable code. Full qualified names are anything but readable.
If anything fully qualified names are the crutch for inexperienced programmers who don't know where things are, code by intellisense, aren't able to hit 'find' in the object browser, or don't have the skill to notice when a conflict occurs.
Programming environments are continually evolving to provide more and more abstraction, which helps us make sense of complex situations. Why anyone would want to make their code more complex and difficult to understand is beyond me.
Regardless, your refactoring tools (even the built in ones) make dealing with your usings a total no-brainer.
|
|
|
|
|
Mark Churchill wrote: Full qualified names are anything but readable.
Not at all, I know when I read "System.Windows.Forms.Button" that it means "System.Windows.Forms.Button", and I don't have to guess that some "Button" may or may not be some other type of "Button" whose actual heritage is concealed (well, that's too strong a word actually) in a line waaay the ffff up at the top of the file.
Don't think of fully-qualified names as being for you, think of them as for they who come after you.
A case in point:
In yesterday's "Friday Programming Quiz" there is a snippet of code that refers to, among other things, mshtml.IHTMLInputElement , that's a fully-qualified name, so even though I've never heard of such a beast, I had little trouble tracking it down. Had the poster not fully-qualified the name (he didn't include a using directive, remember) I would have had a more difficult time.
|
|
|
|
|
You can (and I do) write C# programs with absolutely no using directives.
I feel it improves readability, while most others think otherwise.
Does the using directive solve an actual programming problem?
(Not just reducing keystrokes, footprint on disk, whatever)
|
|
|
|
|
private void txtBody_TextChanged(object sender, eventArgs e)<br />
{<br />
if(tbWordwrap.Pushed)<br />
{<br />
string[] tempArray = new string(txtBody.Lines.length);<br />
tempArray = txtBody.Lines;<br />
<br />
int Prevsel = txtBody.SelectionStart;<br />
string Op = "";<br />
int maxLength = cINI.dbUtils.Pref.DefaultEditorWidth;<br />
bool change= false;<br />
<br />
for(int cou = 0; cou < tempArray.Length; cou++)<br />
{<br />
if (tempArray[cou].length > maxLength)<br />
{<br />
string words = tempArray[cou].split(' ');<br />
int currentLine Length = 0;<br />
string currentLine = "";<br />
foreach(string currentWords in words)<br />
{<br />
if(currentWord.Length > 0)<br />
{ <br />
if(currentword.Length >= maxLength)<br />
{<br />
Op +=currentword.Insert(maxLength, "\r\n");<br />
break;<br />
}<br />
if(currentLineLength + currentword.Length + 1 < maxLength)<br />
{<br />
currentLine += currentword + " ";<br />
currentLineLength += currentword.Length +1;<br />
}<br />
else<br />
{<br />
Op +=currentLine.Insert(currentLineLength, "\r\n");<br />
currentLine = currentWord;<br />
currentLineLength = currentWord.Length;<br />
}<br />
}<br />
}<br />
if(currentLine !="")<br />
Op += currentLine;<br />
<br />
<br />
PrevSel++;<br />
change = true;<br />
}<br />
else<br />
{<br />
Op += tempArray[cou] + "\r\n";<br />
}<br />
if(change)<br />
{<br />
txtBody.Text = Op;<br />
txtBody.SelectionStart = prevSel;<br />
}<br />
}<br />
<br />
Op += tempArray[cou].Insert(maxLength, "\r\n" );<br />
Prevsel++;<br />
change= true;<br />
}<br />
else<br />
{<br />
Op += tempArray(cou) + "\r\n";<br />
}<br />
}<br />
<br />
if(change)<br />
{<br />
txtBody.Text = Op;<br />
txtbody.SelectionStart = Prevsel;<br />
}<br />
}<br />
}<br />
<br />
<br />
The above code is for text_change event of RichText Box in C# vs.net 2003.
Its working fine, But there are some problem which i am i m unable to understand why r coming,
1. In rare cases there occurs a problem like it automatically gives spaces between two letters, like "Him". It gives "H i m",
2. Also dont know why its cuts the word at end of line, like Accept is word,
then Acc to upper line ept to next line, This also comes rarely.
I m unableto short out the problem plz, help.
Here maxLength is variable where user can put no. of chracters he wants in a line, like 65, 68, etc.
|
|
|
|
|
humdumof wrote: = new string(txtBody.Lines.length);
This is a waste of time, you assign the variable to a different array in the next line
Your code is very messy. It should use stringbuilders instead of concatenating strings.
You should experiment with known strings until you find one that shows your bug, then step through the debugger to see what's going wrong.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
some suggestions:
1.
when showing code, put it in PRE tags so it preserves indentation; as it is,
it is very hard to read.
2.
your code does not compile; it has:
- a String.Split with lower-case
- the line int currentLine Length = 0; is invalid
- a mismatch in { and }
etc
3.
you are trying to do word wrap yourself; why don't you use LastIndexOf(' ',maxLength)
where maxLength is your linewidth limit, to find where the offending word begins?
4.
you have a lot of \r\n; I believe in RTB a single \n is what is required for
line breaks. It is my guess those \r will be turned somehow into spaces,
resulting in some of the phenomena you are experiencing.
The above list is not complete.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hello Everyone...
I have a question about two form want to access global variable
like below, i create three classes, main class and two inner class,
but i don't why couldn't compile successful ?
If I want do this how should i to do?
<br />
namespace Innerclass<br />
{<br />
class Program<br />
{<br />
public string Share1 = "Share_Temp1";<br />
public string Share2 = "Share_Temp2";<br />
static void Main(string[] args)<br />
{<br />
object obj = new object();<br />
obj = Program.<br />
}<br />
class ClassA<br />
{<br />
public ClassA()<br />
{<br />
<br />
System.Console.WriteLine("Class A Constructor init.");<br />
System.Console.WriteLine("Class A Constructor init.--" + Share1);<br />
System.Console.WriteLine("Class A Constructor init.--" + Share2);<br />
}<br />
<br />
}<br />
class ClassB<br />
{<br />
public ClassB()<br />
{<br />
System.Console.WriteLine("Class B Constructor init.");<br />
System.Console.WriteLine("Class B Constructor init.--" + Share1);<br />
System.Console.WriteLine("Class B Constructor init.--" + Share2);<br />
}<br />
<br />
}<br />
}<br />
}<br />
By AYR
itsayr@gmail.com
|
|
|
|
|
Hi
in the code you sent,you must declare Share1 and Share2 variables as static members to work ,or pass an instance of Program class to ClassA and ClassB (is not a good choice for program class).
the only difference for inner classes in this usage is they can access the private members too.
here is the example from yours
namespace Innerclass
{
class Program
{
public static string Share1 = "Share_Temp1";
private static string Share2 = "Share_Temp2";
private string Share3 = "Share_Temp3";
public string Share4 = "Share_Temp4";
static void Main(string[] args)
{
Program prg = new Program();
ClassA clsA = new ClassA(prg);
ClassB clsB = new ClassB(prg);
}
class ClassA
{
public ClassA(Program prg)
{
System.Console.WriteLine("Class A Constructor init.");
System.Console.WriteLine("Class A Constructor init.--" + Share1 );
System.Console.WriteLine("Class A Constructor init.--" + Share2);
System.Console.WriteLine("Class A Constructor init.--" + prg.Share3);
System.Console.WriteLine("Class A Constructor init.--" + prg.Share4);
}
}
class ClassB
{
public ClassB(Program prg)
{
System.Console.WriteLine("Class B Constructor init.");
System.Console.WriteLine("Class B Constructor init.--" + Share1);
System.Console.WriteLine("Class B Constructor init.--" + Share2);
System.Console.WriteLine("Class B Constructor init.--" + prg.Share3);
System.Console.WriteLine("Class B Constructor init.--" + prg.Share4);
}
}
}
}
good luck
|
|
|
|
|
AYR Chen wrote: object obj = new object();
This is a waste of time, you reassign obj in the next line
AYR Chen wrote: obj = Program.
This obviously won't compile. What are you trying to do ?
AYR Chen wrote: I have a question about two form want to access global variable
like below, i create three classes, main class and two inner class,
Instead, your two forms should use delegates to communicate the variable value to each other as it changes, and get rid of the global.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Please show code using PRE tags (not CODE tags);
I can't understand it without proper indentation.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi All ,
I have got a problem in setting tool tip in maximize, minimise and close boxes of a form which r on the top right corner of a form . I don't know ho to do it .
Please tell me, how i can do it?
Thanx.
Praveen Sharma
|
|
|
|
|
dear sir,
i want read an excel file and open it to listview but now two exception throws would u help me.....its very urgent.
exceptions:
==============
1. No overload for method 'Open' takes '13' arguments
2. Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Excel.Range.get_Value(object)' or 'Excel.Range.set_Value(object, object)'
source code:
===============
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//using System.Office.Interop.Excel;
//private Excel.Application ExcelObj = null;
namespace Project_test1
{
public partial class Form1 : Form
{
private Excel.Application ExcelObj = null;
public Form1()
{
// Initialize the Windows Components
InitializeComponent();
ExcelObj = new Excel.Application();
// See if the Excel Application Object was successfully constructed
if (ExcelObj == null)
{
MessageBox.Show("ERROR: EXCEL couldn't be started!");
System.Windows.Forms.Application.Exit();
}
// Make the Application Visible
ExcelObj.Visible = true;
}
string[] ConvertToStringArray(System.Array values)
{
// create a new string array
string[] theArray = new string[values.Length];
// loop through the 2-D System.Array and populate the 1-D String Array
for (int i = 1; i <= values.Length; i++)
{
if (values.GetValue(1, i) == null)
theArray[i - 1] = "";
else
theArray[i - 1] = (string)values.GetValue(1, i).ToString();
}
return theArray;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btn_Click(object sender, EventArgs e)
{
// prepare open file dialog to only search for excel files (had trouble setting this in design view)
this.openFileDialog1.FileName = "*.xls";
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
// Here is the call to Open a Workbook in Excel
// It uses most of the default values (except for the read-only which we set to true)
Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(openFileDialog1.FileName, 0, true, 5,
"", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true);
// get the collection of sheets in the workbook
Excel.Sheets sheets = theWorkbook.Worksheets;
// get the first and only worksheet from the collection of worksheets
Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1);
// loop through 10 rows of the spreadsheet and place each row in the list view
for (int i = 1; i <= 3; i++)
{
Excel.Range range = worksheet.get_Range("A" + i.ToString(), "J" + i.ToString());
System.Array myvalues = (System.Array)range.Cells.Value;
string[] strArray = ConvertToStringArray(myvalues);
listView1.Items.Add(new ListViewItem(strArray));
}
}
}
i add :
=========
Microsoft Excel 9.0 Objects Library.
|
|
|
|
|
shafikshafik wrote: No overload for method 'Open' takes '13' arguments
1 - use intellisense to find out how many arguments you should be providing, and fix your code
2 - call the get/set methods, as it is telling you to do
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Please show code using PRE tags; I can't understand it without proper indentation.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Is there a way to import a pre-written xsd document so I don't have to actually create the schema? With that, is there a way to reference an XML document you are creating at runtime to be referenced to the schema? Thanks in advance.
|
|
|
|
|
hi can anybody let me know is it possible to display child windows using threads or delegates?
thanks
|
|
|
|
|
why would you need to do that anyway?
just display the child window like this form1.Show(this) to make it a child window of the current window that;s it
Rocky
You can't climb up a ladder with your hands in your pockets.
|
|
|
|
|
RameshwerE wrote: threads or delegates?
These are two utterly, totally different things. The latter is trivial, the former is a bad move. You should never interact with UI elements outside of the thread that created them, which should, logically, be your main thread.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
A simple way to do it using timer...
it's like a thread via timer, is it useful to you ?
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Drawing.Imaging;<br />
<br />
namespace OptionFormA<br />
{<br />
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
Timer t = new Timer();<br />
t.Tick += new EventHandler(FormOpen);<br />
t.Start();<br />
<br />
}<br />
<br />
private void FormOpen(object _sender, EventArgs eArgs)<br />
{ <br />
SubFormA sfA = new SubFormA();<br />
sfA.Visible = true;<br />
}<br />
}<br />
}<br />
<br />
<br />
<br />
By AYR
itsayr@gmail.com
|
|
|
|
|
But I have a question about
if i want appear a form after pressing a button on main form
and main form will disappear, and when press a button on
child form the child form will disappear and the main form will
appear ? Does anyone know how to do?
By AYR
itsayr@gmail.com
|
|
|
|
|
just pass the main form to child form and then call Hide method of the main through child or before showing it (from the MainForm)
and you can do that vice versa for showing main again and hiding child
namespace Test2
{
public partial class MainForm : Form
{
ChildForm child;
public MainForm()
{
InitializeComponent();
this.child = new ChildForm(this);
}
private void hideAndShowChld_Click(object sender, EventArgs e)
{
this.Hide();
this.child.Show();
}
}
public partial class ChildForm : Form
{
MainForm main;
public ChildForm(MainForm form)
{
InitializeComponent();
this.main = form;
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
this.main.Show();
}
}
}
good luck
|
|
|
|
|
I want to Build every program in my application < so I need binPath but i don't want to set
binpath by manual and didn't find the path of
binpath in registry please reply me how I can set it automaticly
tankyou
|
|
|
|
|
What is it that you are trying to do? If you are trying to change where your compiled code gets stored after a build, you'll need to go into the project configuration and there you can change the path of your builds.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
How to convert 070818 to 20070818? any one provide solution for me
parthiban
|
|
|
|
|
add 20 to the front of it ? Your question isn't making much sense, I'm afraid. Do you have this as a number, or a string ? what's the hard bit, are you assuming all dates are in the past, or not ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|