quarta-feira, 9 de junho de 2010

Re: How to get a GtkLabel to fill all the available space. - msg#00009 - gnome.devel

Re: How to get a GtkLabel to fill all the available space. - msg#00009 - gnome.devel

Re: How to get a GtkLabel to fill all the available space. - msg#00009

List: gnome.devel

Date: Prev Next Index Thread: Prev Next Index

В Чтв, 05/01/2006 в 11:28 -0500, Hans Deragon пишет:
> Greetings.
>
>
> Under Gnome 2.10, using glade-2, I created a simple window with
> GtkHBox. The GtkHBox as 3 sections, the first a small image, the second
> a label and the tird a small button.
>
> The GtkLabel is the widget that should take all the rest of available
> space. When clicking on it, I see that it seams to be taking it, as the
> border shown with glade-2 confirms it. Yet, the text I have entered,
> multi-line and very long, seams to wrap much before the right border of
> the widget. I tried all sort of stuff, but could not have the text go
> as far as the right border. There seams to be an imaginary boundary in
> the middle of the label where the text wraps.
>
> I noticed that if I increase the width of the widget in pixels, in
> the Properties/Common/width entry, I can sorta fix this. But that means
> I have to enter a specific width. I do not want this. I want for the
> label to expand and wrap as the user changes the size of the window.
>
> This must be a common problem. Probably there is an easy solution I
> simply am not to figure out.
>
>
> Best regards,
> Hans Deragon
> --

Hello Hans

You are correct, it's just an internal hard-coded behaviour of the
GtkLabel with wrapped text. If you just need to have simple label, it
may have sense to implement your own label-like widget.

Otherwise, you should look at gtk_label_ensure_layout function in gtk
sources (there is if (label->wrap) statement). It uses quite hackish
algorithm to determine label's width from layout width, screen width and
so on. Of course, it can be improved. Probably you can suggest something
better. In that case you should search bugzilla for similar bugs,
probably create a bug in bugzilla against gtk and mail a patch to gtk-
devel list.

Re: How to get a GtkLabel to fill all the available space. - msg#00009 - gnome.devel

Re: How to get a GtkLabel to fill all the available space. - msg#00009 - gnome.devel

Re: How to get a GtkLabel to fill all the available space. - msg#00009

List: gnome.devel

Date: Prev Next Index Thread: Prev Next Index

В Чтв, 05/01/2006 в 11:28 -0500, Hans Deragon пишет:
> Greetings.
>
>
> Under Gnome 2.10, using glade-2, I created a simple window with
> GtkHBox. The GtkHBox as 3 sections, the first a small image, the second
> a label and the tird a small button.
>
> The GtkLabel is the widget that should take all the rest of available
> space. When clicking on it, I see that it seams to be taking it, as the
> border shown with glade-2 confirms it. Yet, the text I have entered,
> multi-line and very long, seams to wrap much before the right border of
> the widget. I tried all sort of stuff, but could not have the text go
> as far as the right border. There seams to be an imaginary boundary in
> the middle of the label where the text wraps.
>
> I noticed that if I increase the width of the widget in pixels, in
> the Properties/Common/width entry, I can sorta fix this. But that means
> I have to enter a specific width. I do not want this. I want for the
> label to expand and wrap as the user changes the size of the window.
>
> This must be a common problem. Probably there is an easy solution I
> simply am not to figure out.
>
>
> Best regards,
> Hans Deragon
> --

Hello Hans

You are correct, it's just an internal hard-coded behaviour of the
GtkLabel with wrapped text. If you just need to have simple label, it
may have sense to implement your own label-like widget.

Otherwise, you should look at gtk_label_ensure_layout function in gtk
sources (there is if (label->wrap) statement). It uses quite hackish
algorithm to determine label's width from layout width, screen width and
so on. Of course, it can be improved. Probably you can suggest something
better. In that case you should search bugzilla for similar bugs,
probably create a bug in bugzilla against gtk and mail a patch to gtk-
devel list.

quarta-feira, 2 de junho de 2010

GtkSharp: Widget Colours - Mono

GtkSharp: Widget Colours - Mono

GtkSharp: Widget Colours


Colouring Widgets and Windows

Colouring widgets and windows (which is itself a widget) alluded me for ages due to my basic knowledge of gtk.

Thanks to a tiny example (http://lists.ximian.com/pipermail/gtk-sharp-list/2004-September/004820.html) I found by John Bailo on the gtk# mailing list (http://lists.ximian.com/pipermail/gtk-sharp-list/) it turns out to not be such a tricky thing after all. I’ve recreated it here.

The following code sets up a gtk.window, a DrawingArea widget on top, colours the window and the drawing area both red, then draws a diagonal line across the page.

using System;
using Gtk;

class ColourExample
{
Window win;
DrawingArea da;

static void Main (){
Application.Init ();
new ColourExample ();
Application.Run ();
}

ColourExample(){
win = new Window ("Colour Example");
win.SetDefaultSize (400, 300);
win.DeleteEvent += OnWinDelete;

da = new DrawingArea();
da.ExposeEvent += OnExposed;

Gdk.Color col = new Gdk.Color();
Gdk.Color.Parse("red", ref col);
win.ModifyBg(StateType.Normal, col);
da.ModifyBg(StateType.Normal, col);

win.Add (da);
win.ShowAll ();
}

void OnExposed (object o, ExposeEventArgs args) {
da.GdkWindow.DrawLine(da.Style.BaseGC(StateType.Normal), 0, 0, 400, 300);
}


void OnWinDelete (object o, DeleteEventArgs args){
Application.Quit ();
}
}

The code declares a global Window widget, and a global DrawingArea widget. Then a Gdk.Color object is created. We need to create a Color object so that this can be passed to the .ModifyBg() method of whatever widget is to be coloured. At first, just a blank Gtk.Color object is created.

We still need to tell the object what colour to be. This is done using the Gtk.Color.Parse method. The first parameter is a colour to try and translate. In this example “red” is passed and the method can easily work out what red is. The second parameter is which Gtk.Color object to send the colour to. Of course, this is ‘col’. So in short, declare a Gtk.Color object called ‘col’ and inform it to be a particular colour using Gtk.Color.Parse();

Both widgets are going to be coloured red. I have done this is for two reasons.

One: rarely, does a gtk# application contain just a Window widget and nothing else alone, so we need to put something practical in there and a drawingarea will do fine.

Two: although you really only need to change the background colour in the drawingarea widget to achieve the desired effect, I have elected to colour the window widget as well so that you don’t get an annoying white/grey flick the moment before the drawingarea object appears on the window when the .Show() method is called.

Finally, I used the expose event of the drawingarea widget to draw a simple line to just give the program some real world practicality.

TextReader and TextWriter In C# | C# Help – C# Tutorials Resources

TextReader and TextWriter In C# | C# Help – C# Tutorials Resources


TextReader and TextWriter In C#


INTRODUCTION:

This article covers the information of how toread or write (Unicode) character based data through TextReader andTextWriter. The TextReader and TextWriter are base classes. TheStreamReader and StringReader derives from the abstract typeTextReader. Similarly the StreamWriter and StringWriter derives fromthe abstract type TextWriter.

STREAMWRITERS & STREAMREADERS:

As I mentioned earlier StreamWriter typederives from a base class named TextWriter. This class defines membersthat allow derived types to write textual data to a given characterstream.

Let us see some of the main members of the abstract class TextWriter.

1.close() — Closes the Writer and frees any associated resources.
2.Write() — Writes a line to the text stream, with out a newline.
3.WriteLine() — Writes a line to the text stream, with a newline.
4.Flush() — Clears all buffers.

WRITING – TEXT FILE:

Let us see the Writing to a Text File with a example.

Before we move into writing to a text file wehave to know about "FileInfo" class. What is FileInfo? In the frameworkof .NET , the system.IO namespace is the region of the base classlibraries devoted to file-based input and output services.File Info isone of the core type of System.IO Namespace.The function of the FileInfo is to encapsulate a number of detailsregarding existing files on your hard drive (size,fileattributes,creating time,etc.)as well as aid in the creation anddestruction of new files. Let us move to example.

In this example in the Writetextfile class Icreate a file named "Arungg.txt" using the FileInfo class. Aftercreating the text file using the CreateText() method, I get aStreamWriter and write some textual data to the newly created textfile. We can also add numeric data into the text file.

public class Writetextfile

{
public static int Main(sting[] args)
{
FileInfo t = new FileInfo("Arungg.txt");
StreamWriter Tex =f.CreateText();
Tex.WriteLine("Arungg has launced another article");
Tex.WriteLine("csharpheaven is the new url for c-sharpcorner");
Tex.Write(Tex.NewLine);
Tex.close;
Console.WriteLine(" The Text file named Arungg is created ");
}
}

If you open the text file the data is entered there.

READING – TEXT FILE:

Now let us see how to read a text file using the StreamReader type.

Let us see some of the main members of the abstract class TextReader.

1.Read() — Reads data from an input stream.
2.ReadLine() — Reads a line of characters from the current stream and returns the data as a string.
3.ReadToEnd() — Reads all characters to the end of the TextReader and returns them as one string.

public class Readtextfile
{
public static int Main(string[] args)
{
StreamReader re = File.OpenText("Arungg.txt");
string input = null;
while ((input = re.ReadLine()) != null)
{
Console.WriteLine(input);
}
re.close;
return 0;
}
}

In the above class Readtextfile I open the text file Arungg.txt and read the contents using the ReadLine() method.In both StreamReader and StreamWriter are concerned with moving text data to and from a specified file.

STRINGWRITERS & STRINGREADERS:

Using the StringReaders and StringWriters cantreat textual information as a stream of in-memory characters. In thiswe can insert or remove string between a block of textual data.Let us see a program in which I add and delete some string between ablock of text.Running the above program we get the textual data in the console.

The output:

Data:
Friendship is not a two way road.
It is a one way road travelled by two people.

Press any key to continue

Now I show you how to insert and delete some string between textual data.

using System.Text;

public class stringwrite
{
public static int Main(string[] args)
{
StringWriter wr = new StringWriter();
wr.WriteLine("Friendship is not a two way road.");
wr.WriteLine("It is a one way road travelled by two people.");
wr.Write(Writer.NewLine);
wr.close();

StringBuilder bu = wr.GetStringBUilder();
string entiredata = bu.ToString();
Console.WriteLine("The data:{\n0}",entiredata);
// TO ADD SOME STRING.

bu.Insert(45,"together-hand in hand");
entiredata = bu.ToString();
Console.WriteLine("The modified data:\n{0}",entiredata);

// TO REMOVE SOME STRING.

bu.Remove(45."together-hand in hand".Length);
entiredata = bu.ToString
Console.WriteLine("The original data:\n{0}",entiredata);
return 0;
}
}

In the above program I write some characterdata to a StringWriter type and modify the data by inserting some itemto buffer at position 45.After inserting I also show how to remove someparticular string from the data.

The Output:

The Data:
Friendship is not a two way road.
It is a one way road travelled by two people.

The modified data:
Friendship is not a two way road.
It is a one way road travelled by two people together-hand in hand.

The original data:
Friendship is not a two way road.
It is a one way road travelled by two people.

Now Let us see how to use StringReader to read a block of character data rather than a entire file.

StringReader re = new StringReader(wr.ToString());

string input = null;
while(( input = re.ReadLine()) != null)
{
Console.Write\line(input);
}
re.close();

Like the above way by using StringReader we can read data from a file.

CONCLUSION:

I hope after reading this article , the userhas gained some information about how to create,write and read in atext file using TextReader and TextWriter in C# and also somethingabout Friendship!.

Related Articles :