|
That definately changes things. You really can't depend on the RTB's Selection highlight to work the way you need it to. You'll have to implement your won line tracking code and draw the highlight yourself. In which case, my original suggestion for changing the textcolor still stands. You just need to add code to track which line is currently selected and manage the drawing of the highlight. You've already got most of the pieces, including the buttons to move the highlight up and down.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
...and that's what I was asking I've got the code to track which line is currently selected, I just don't know how to manage the drawing of the highlight - there doesn't seem to be any method to do it. Looking through the Studio Help yesterday I thought I saw something about inserting text with rtf tags or something, but I don't know what these tags would be and I can't find that bit of Help now anyway :-/
Ian.
|
|
|
|
|
The RichTextBox doesn't provide methods to set the text background color by default, although the underlying RichEdit control can do this.
You can, however, create the neccessary methods fairly easily using P/invoke.
Take a look at this article[^], towards the end you'll see how you can set only selected font properties for selected text (something the standard RTB cannot do as well). Along the same lines you can add a SetSelectionBackColor() to highlight the line.
Regards,
mav
|
|
|
|
|
Thanks for the pointer - I've nearly got it working, but there's one thing that doesn't seem to work and I can't figure out why.
I've got a RichTextEx class in which I'm implementing a "Highlight" method which is supposed to swap the foreground and background colours, so before setting the colours I'm using SendMessage to get the existing colours for the selection. Trouble is, crBackColor always comes back as 0 - here's a snippet of my code:
CHARFORMAT2 structure:
[ StructLayout( LayoutKind.Sequential )]
private struct sCharFormat2
{
public int cbSize;
public UInt32 dwMask;
public UInt32 dwEffects;
public Int32 yHeight;
public Int32 yOffset;
public Int32 crTextColor;
public byte bCharSet;
public byte bPitchAndFamily;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=32)]
public char[] szFaceName;
public UInt16 wWeight;
public Int16 sSpacing;
public Int32 crBackColor;
public UInt32 lcid;
public UInt32 dwReserved;
public Int16 sStyle;
public UInt16 wKerning;
public byte bUnderlineType;
public byte bAnimation;
public byte bRevAuthor;
public byte bReserved1;
}
Code that uses SendMessage to fill the structure:
SuspendLayout();
Select(a_intFrom, a_intLength);
sCharFormat2 CharFormat = new sCharFormat2();
CharFormat.cbSize = Marshal.SizeOf(CharFormat);
CharFormat.dwMask = CFM_COLOR | CFM_BACKCOLOR;
CharFormat.dwEffects = CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR;
IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(CharFormat));
Marshal.StructureToPtr(CharFormat, lParam, false);
intRes = SendMessage(Handle, EM_GETCHARFORMAT, SCF_SELECTION, lParam);
CharFormat = (sCharFormat2)Marshal.PtrToStructure(lParam, typeof(sCharFormat2));
Anyone see what's wrong?
Ian.
|
|
|
|
|
Hi!
From a first look at the code it could be the CFE_AUTOBACKCOLOR flag.
Try removing it and see if it helps.
Regards,
mav
|
|
|
|
|
I've just removed the flag - no difference I'm afraid
Ian.
|
|
|
|
|
After more experimentation, it seems that the dwMask member is ignored - EM_GETCHARFORMAT always returns everything. The weird thing is that crBackColor comes back as 0 when the background is white, but if it's any other colour it's correct. Looks like it's kludgetime... :-/
Thanks to all for input
Ian.
|
|
|
|
|
Hi for all
I created an application to connect to my client to play NavyBattle.
When the application run, it's locked when the Socket is receiving the socket sended by method AcceptSocket of TcpListener. The application' s form doesn't show. I saw the taskmanager processes, and it's there.
Can someone aswer my question?
The code are below:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace TcpNavyBattle
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label ConnexionLabel;
private System.Windows.Forms.TextBox TxtLocation;
private bool bConnected;
private Server m_Player1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
Server Player1 = new Server();
m_Player1 = Player1;
//Player1.Running();
//bConnected = Player1.IsConnected();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#Code generated by Visual Sutdio
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
protected void TxtLocation_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(bConnected)
{
if(e.KeyCode == Keys.Enter && TxtLocation.Text != null)
{
ConnexionLabel.Text = "Value inserted";
m_Player1.Write(TxtLocation.Text);
}
else
{
ConnexionLabel.Text = "Connection closed or textbox is null";
}
}
else
{
MessageBox.Show("nada");
}
}
}
public class Server
{
TcpListener ServerListener;
Socket Connexion;
NetworkStream DataStream;
StreamReader Reader;
StreamWriter Writer;
string sData;
public Server()
{
IPAddress IPLocalhost = IPAddress.Parse("127.0.0.1");
//first commandment: create the listener
ServerListener = new TcpListener(IPLocalhost, 65000);
//second commandment: start it!
ServerListener.Start();
}
public void Running()
{
try
{
//third commandment: associate the Listener with the socket to receive data
while(true)
{
Connexion = ServerListener.AcceptSocket();
if(Connexion.Connected)
{
//Put 1252 in (static)GetEncoding method for windows operating system encoding
//System.Text.Encoding FormattedEncoding = System.Text.Encoding.GetEncoding(0);
DataStream = new NetworkStream(Connexion);
Reader = new StreamReader(DataStream);
Writer = new StreamWriter(DataStream);
while(DataStream != null && sData != "Close connection")
{
sData = Reader.ReadLine();
}
}
}
Reader.Close();
Writer.Close();
DataStream.Close();
Connexion.Close();
Application.Exit();
}
catch(SocketException SocketEx)
{
MessageBox.Show(SocketEx.Message);
}
}
public bool IsConnected()
{
return Connexion.Connected;
}
public void Write(string sData)
{
Writer.WriteLine(DataStream);
}
}
}
|
|
|
|
|
You need to create a seperate thread for your listening socket, otherwise your user interface is blocked due to the infinite while-loop.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
I am using C# to insert a date value from the DatePicker into a DateTime filed in mySQL database.. I am using the following syntax:
'" + datePicker.Value + "'
I also triend it withour the ' and with #
in the best scenario I will not get any error but the value will not be saved in the database, so if I have 10 different values of string, numeric & date then everything will be inserted successfully except the date value which will not be inserted and will not return any error message..
can anyone help please.....
Jassim Rahma
|
|
|
|
|
|
hi.
i had some problems with insertion & update of date in sql, and i solved it by using parameters to a command, but u have to be carefull because the character that shows the command that there is a parameter differs from server to server.
for example: (C#)
- to a sql server u would have something like this:
SqlCommand command = new SqlCommand("insert into mytable values (...,@date,...)");
SqlParameter parameter = new SqlParameter("@date", DateTime.Now);
command.Parameters.Add(parameter);
command.ExecuteNonQuery();
the parameter here is: "@date"
- to an oracle server the parameter characther is ":" and u would have something like this: ":date".
and if this doesn't help, u could try to use a stored procedure
best regards.
MetalSandman.
|
|
|
|
|
|
|
|
Bye!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello
I'm creating a new file in my application, but how do I make it hidden?
thanks!
|
|
|
|
|
<code>File.SetAttributes(filepath, File.GetAttributes(filepath) | FileAttributes.Hidden);</code>
|
|
|
|
|
that simple huh?
thanks!
|
|
|
|
|
Dear Friend,
I am doing a research porject about Images. Therefore
I would like to know from you, how to generate an
Image using a ByteCode of an origional image or from a
HexaView of an origional Image. What I need is, a
Java or C# function or DLL to regenarate a copy of an
Image. I can convert a given Image(any format) to the
HexView or to the ByteCode. Hence I need to regenarate
a copy of that Image using the extracted ByteCode or
HexView.
I am waiting for an imediate reply from YOu.
Pls Help me out.
mdkrishan@yahoo.com
md_kpnp@mail.com
mdkrishan@gmail.com
|
|
|
|
|
Dear Friend,
I am doing a research porject about Images. Therefore
I would like to know from you, how to generate an
Image using a ByteCode of an origional image or from a
HexaView of an origional Image. What I need is, a
Java or C# function or DLL to regenarate a copy of an
Image. I can convert a given Image(any format) to the
HexView or to the ByteCode. Hence I need to regenarate
a copy of that Image using the extracted ByteCode or
HexView.
I am waiting for an imediate reply from YOu.
Pls Help me out.
mdkrishan@yahoo.com
md_kpnp@mail.com
mdkrishan@gmail.com
|
|
|
|
|
Hello.
I have an application that uses dataadapters to fill some datasets, and it works just fine, but sometimes it crashes and i get to following error: "System.NullReferenceException: Object not set to an instance of an object".
The whole error is:
Severity=5,OccurenceTime=10.06.2005 16:23:02,Class=Data.DbManager,Method=FillTable,Message=System.NullReferenceException: Object reference not set to an instance of an object.
at System.Data.DataTable.LoadDataRow(Object[] values, Boolean fAcceptChanges)
at System.Data.Common.SchemaMapping.LoadDataRow(Boolean clearDataValues, Boolean acceptChanges)
at System.Data.Common.DbDataAdapter.FillLoadDataRow(SchemaMapping mapping)
at System.Data.Common.DbDataAdapter.FillFromReader(Object data, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable, IDataReader dataReader)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at Data.DbManager.FillTable(DataTable table, String commandText),Stack= at System.Data.DataTable.LoadDataRow(Object[] values, Boolean fAcceptChanges)
at System.Data.Common.SchemaMapping.LoadDataRow(Boolean clearDataValues, Boolean acceptChanges)
at System.Data.Common.DbDataAdapter.FillLoadDataRow(SchemaMapping mapping)
at System.Data.Common.DbDataAdapter.FillFromReader(Object data, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable, IDataReader dataReader)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at Data.DbManager.FillTable(DataTable table, String commandText)
Can u please help me? It's very unpseting that the application works and then suddenly crashes
Thanks.
MetalSandman.
|
|
|
|
|
can you post the specific code section where the exception is thrown plz ?
|
|
|
|
|
i get the error with this fill:
"IDbCommand command = DbManager.GetCommandWithDefaultOpenConnection(commandText);
((SqlDataAdapter)GetDataAdapter(command)).Fill(table);
command.Connection.Close();"
the GetDataAdapter function:
"IDbDataAdapter dataAdapter = null;
dataAdapter = new SqlDataAdapter((SqlCommand)command);"
the getCommandWithDefaultOpenConnection function:
"IDbCommand command = null;
command = new SqlCommand();
command.CommandText = commandText;
command.Connection = GetNewOpenDefaultConnection();"
hope this helps.
MetalSandman
|
|
|
|
|
Somehwere along this line of code, you're attempting to use an object that wasn't created. For instance:
IDbCommand command = DbManager.GetCommandWithDefaultOpenConnection(commandText);
((SqlDataAdapter)GetDataAdapter(command)).Fill(table);
command.Connection.Close();
Did .GetCommandWithDefaultOpenConnection(commandText) actually return an object? You don't know because you didn't check for it before you attempted to use its .Fill(table) method.
Another couple questions would be, does that table parameter represent an actual object or is it possible that it it a Null reference. Does the GetDataAdapter(command) method call actually return an object?
You're making all these calls to create objects, but your code is assuming that they all worked. It's never checking the return values of any of these calls, and therefore, you have a failure (NullReferenceException) that you cannot easily trace down.
Oh, as a side-bar, you can only have one active DataAdapter per Connection object.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|